Android:所有设备的多屏幕支持

时间:2016-04-02 19:56:04

标签: android

我正在研究我的android项目,并且不知道有什么叫做多屏幕支持。我认为开发一种解决方案在其他方面是相同的。但是我错了。目前我设计的应用程序使用1080 * 1920分辨率。但我希望它支持至少下面提到的所有屏幕分辨率。

480 * 800, 1080 * 1920(支持), 720 * 1280,
480 * 854, 480 * 960, 320 * 480, 1440 * 2560

那么在这方面可以做些什么。我不知道在这里发布什么代码。请指导我完成这个。谢谢

credits.xml

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f6f6f6">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="The Team"
        android:id="@+id/textView3"
        android:textSize="40sp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:textColor="#ff4a3b" />

    <ImageView
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:layout_marginTop="8dp"
        android:layout_marginRight="20dp"
        android:id="@+id/imageView2"
        android:src="@mipmap/ic_launcher"
        android:layout_below="@+id/textView3"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="32dp"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="PRAVEEN"
        android:id="@+id/textView4"
        android:textSize="15sp"
        android:textColor="#010101"
        android:layout_below="@+id/imageView2"
        android:layout_alignRight="@+id/imageView2"
        android:layout_alignEnd="@+id/imageView2"
        android:typeface="monospace" />

    <ImageView
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:layout_marginTop="8dp"
        android:layout_marginLeft="30dp"
        android:id="@+id/imageView"
        android:src="@mipmap/ic_launcher"
        android:layout_below="@+id/textView3"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="74dp"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="AKASH"
        android:id="@+id/textView5"
        android:textSize="15sp"
        android:textColor="#010101"
        android:typeface="monospace"
        android:layout_below="@+id/imageView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />


    <ImageView
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:layout_marginTop="165dp"
        android:layout_marginRight="20dp"
        android:id="@+id/imageView3"
        android:src="@mipmap/ic_launcher"
        android:layout_below="@+id/textView3"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="32dp"
        android:layout_marginTop="157dp"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="PRANOTI"
        android:id="@+id/textView6"
        android:textSize="15sp"
        android:textColor="#010101"
        android:layout_below="@+id/imageView2"
        android:layout_alignRight="@+id/imageView2"
        android:layout_alignEnd="@+id/imageView2"
        android:typeface="monospace" />

    <ImageView
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:layout_marginTop="165dp"
        android:layout_marginLeft="30dp"
        android:id="@+id/imageView6"
        android:src="@mipmap/ic_launcher"
        android:layout_below="@+id/textView3"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="72dp"
        android:layout_marginTop="157dp"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="SONAL"
        android:id="@+id/textView8"
        android:textSize="15sp"
        android:textColor="#010101"
        android:typeface="monospace"
        android:layout_below="@+id/imageView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="361dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="GUIDE"
        android:id="@+id/textView67"
        android:textSize="30sp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:textColor="#ff4a3b" />

    <ImageView
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:id="@+id/imageView69"
        android:src="@mipmap/ic_launcher"
        android:layout_below="@+id/textView67"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"

        android:text="Prof. M.G.Huddar"
        android:id="@+id/textView89"
        android:textSize="15sp"
        android:textColor="#010101"
        android:typeface="monospace"
        android:layout_below="@+id/imageView69"
        android:layout_toLeftOf="@+id/textView6"
        android:layout_toStartOf="@+id/textView6" />

</RelativeLayout>

    </ScrollView>

3 个答案:

答案 0 :(得分:1)

您需要创建5个文件夹。

可绘制-MDPI

可绘制-HDPI

可绘制-xhdpi

可绘制-xxhdpi

可绘制-xxxhdpi

或者您也可以使用默认文件夹

Mip映射MDPI

Mip映射HDPI

Mip映射xhdpi

Mip映射xxhdpi

Mip映射xxxhdpi

在这些所有文件夹中,您需要保持图像的比例为1:1.5:2:3:4。

所有相似的图像都有相同的名称。

现在其他事情自动完成,当有人使用360 * 480(hdpi)的设备时。然后它会自动从hdpi文件夹中获取图像。

图像示例。

如果我们拍摄图像

mdpi,100dp * 100dp。

然后是hdpi: - 150dp * 150dp

xhdpi:200dp * 200dp

xxhdpi:300dp * 300dp

xxxhdpi:400dp * 400dp

答案 1 :(得分:1)

支持多个设备令人头疼。它曾经使用hdpi,mdpi,xhdip,xxhdip来指定不同的设备大小。现在,它使用sw320dp,sw360dp,sw600dp等。 sw 代表最小宽度 dp 代表密度无关的像素。所以,

如果您在 res / layout-sw360dp 文件夹中创建布局文件 activity_main.xml ,则该文件将用于屏幕宽度为&gt; = 360dp的设备。现在,如果您创建另一个名称为 activity_main.xml 但位于文件夹 res / layout-sw600dp 的文件,则此文件将用于屏幕宽度为&gt的设备; = 600dp。

这也适用于drawable,dimen和value文件。

res / drawable-sw360dp适用于屏幕宽度> = 360dp

的设备

res / drawable-sw600dp适用于屏幕宽度> = 600dp

的设备

res / drawable-sw720dp适用于屏幕宽度> = 720dp

的设备

你明白了......

关于这一点,我写了一篇postOfficial DocDevice Size Metrics

答案 2 :(得分:0)

Android设备有多种密度,分类为ldpi(低),mdpi(中),hdpi(高)和xhdpi(超高)。通常,设备的分辨率越高,其密度越高。所以低分辨率设备有ldpi,中等设备有mdpi等等。要实现这一点,请转到资源文件夹并创建一些名为drawable-ldpi,drawable-mdpi,drawable-hdpi,drawable-xhdpi的新文件夹,并将图像放入其中。 drawable-ldpi中的图像应具有较低的分辨率,并将自动用于分辨率较低的设备(您无需以编程方式实现此功能)。 drawable-mdpi中的图像应该具有比ldpi更高的分辨率,依此类推。像这样你可以确保每个设备都能获得正确的图像。您可以将图像放在所有这些文件夹中,而无需重命名。例如,您可以在所有这些文件夹中放置一个名为image.png的文件,当通过R.id.image访问它时,系统将自动选择它将在哪个文件夹中查找。希望这有帮助!

相关问题