【发布时间】:2010-11-11 09:08:04
【问题描述】:
我正在尝试开发一个需要多屏支持的应用。我已阅读有关多屏幕支持的最佳实践的 Android 文章。根据文章,我们必须遵循 3 件重要的事情:
- 在 AndroidManifest.xml 中提及对不同屏幕尺寸(大、中、小)和任何密度的支持。
- 将 3 dpi(120、160、240)的图像放在 3 个文件夹 res/ldpi、res/mdpi 和 res/hdpi 中。
- 在布局中,尺寸应以“倾角”单位表示。然后 Android 将自行处理缩放。
我已经在我的项目中实现了所有这些要点。从适当的文件夹中正确拾取图像。但控件的排列方式不一样。
例如我在三个模拟器上运行该应用程序
1.分辨率 240*320 dpi 120。
2。分辨率 240*320 dpi 160。
3。分辨率 240*320 dpi 240。
(所有模拟器分辨率相同,但密度不同。)
问题是所有三个模拟器上的控件位置都不相同。根据我的理解,如果“dip”中提到了 android:layout_marginLeft 和 android:layout_marginTop,那么这个问题应该不会发生。随着模拟器密度的增加,控件会更靠右放置。
是否绝对有必要为所有屏幕尺寸和密度组合提供布局,即使所有设备的布局都相同?
我错过了一些重要的点吗?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:src="@drawable/bgd" android:scaleType="fitXY">
</ImageView>
<ImageView android:id="@+id/wtButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/button" android:layout_marginLeft="170dip"
android:layout_marginTop="9dip"></ImageView>
<ImageView android:id="@+id/htButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/button2" android:layout_marginLeft="220dip"
android:layout_marginTop="90dip"></ImageView>
</RelativeLayout>
图片:
【问题讨论】:
-
能否请您发布一些示例屏幕截图和您的布局 XML。
-
愚蠢的想法:你不认为它实际上是正确缩放的,只是模拟器不能正确显示多个密度大小? (这是有道理的,模拟器不能完全改变物理屏幕上的像素,只能缩放以“模拟”各种密度)
-
遇到了同样的问题,希望能找到答案