【发布时间】:2016-09-27 05:21:20
【问题描述】:
我制作了一个包含 3 个图像的 XML 文件。首先,即使我使用“dp”作为图像尺寸,我也不清楚为什么不同屏幕尺寸上的图像尺寸不同。 所以接下来我所做的是,我为不同的屏幕尺寸制作了不同的布局文件。我看到的还有一个问题是,从 3.5 英寸到 5 英寸的大多数屏幕都是由 normal\something.xml 处理的。并且3.5英寸屏幕出现的图像尺寸与5英寸屏幕不同。
这是正常的 XML 文件\something.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#add8e6"
android:orientation="vertical"
android:id="@+id/mood">
<TextView
android:layout_width="match_parent"
android:layout_height="15dp"
/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="33sp"
android:text="How's your Mood ?"
android:gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginBottom="30dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="15dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:orientation="horizontal"
android:id="@+id/happyLayout"
android:background="#85a9b4">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:id="@+id/happyRadio"
android:textSize="30sp"
/>
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/happy"
android:layout_marginLeft="30dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:orientation="horizontal"
android:id="@+id/sickLayout">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:id="@+id/sickRadio"/>
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/sick"
android:layout_marginLeft="30dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:orientation="horizontal"
android:id="@+id/sadLayout">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:id="@+id/sadRadio"/>
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/sad"
android:layout_marginLeft="30dp"/>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#f4880d"
android:text="ADD MOOD"
android:textColor="#ffffff"
android:textSize="30sp"/>
</LinearLayout>
以上文件适用于普通屏幕尺寸。对于大屏幕和小屏幕,我只是将图像的尺寸更改为更低或更高的“dp”值(如果这种方法不正确,请纠正我)。
如果您能建议我应该遵循的方法来处理不同屏幕尺寸和密度的图像尺寸,那就太好了。
【问题讨论】:
-
是否已按密度添加图片,即mdpi、hdpi或xhdpi?
-
根据屏幕大小将图像放置在不同密度的文件夹中,即drawable(mdpi)、drawable(hdpi)、drawable(xhdpi)。而密度是这样的 mdpi(1.0 Baseline), hdpi(1.5), xhdpi(2.0)
-
所以如果我像你说的那样使用不同尺寸的图像,那么不同的图像将用于屏幕尺寸 3.7 和 5.7"?我问是因为这两种屏幕尺寸在 Android 开发中都被认为是正常的这两种屏幕尺寸都使用工具和相同的布局文件 normal/something.xml。
-
有关不同密度的 Android 设备的信息。点击这里-stackoverflow.com/a/44924525/4082923