【问题标题】:Layout issues related to Multiple Screens Support与多屏幕支持相关的布局问题
【发布时间】:2010-11-11 09:08:04
【问题描述】:

我正在尝试开发一个需要多屏支持的应用。我已阅读有关多屏幕支持的最佳实践的 Android 文章。根据文章,我们必须遵循 3 件重要的事情:

  1. 在 AndroidManifest.xml 中提及对不同屏幕尺寸(大、中、小)和任何密度的支持。
  2. 将 3 dpi(120、160、240)的图像放在 3 个文件夹 res/ldpi、res/mdpi 和 res/hdpi 中。
  3. 在布局中,尺寸应以“倾角”单位表示。然后 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。
  • 愚蠢的想法:你不认为它实际上是正确缩放的,只是模拟器不能正确显示多个密度大小? (这是有道理的,模拟器不能完全改变物理屏幕上的像素,只能缩放以“模拟”各种密度)
  • 遇到了同样的问题,希望能找到答案

标签: android layout screen


【解决方案1】:

是的,您必须在清单文件中添加以下内容,然后才需要 根据需要从 ldpi、mdpi、orhdpi 中获取资源

   <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:resizeable="true"
        android:smallScreens="true"
        android:xlargeScreens="true" />

    <compatible-screens>
 <screen
            android:screenDensity="mdpi"
            android:screenSize="mediaum" />      
  <screen
            android:screenDensity="hdpi"
            android:screenSize="large" />
        <screen
            android:screenDensity="xhdpi"
            android:screenSize="large" />
    </compatible-screens>

【讨论】:

【解决方案2】:

首先你计算设备的高度和宽度

那么如果你想设置 180 作为 leftpadding 值和 48 作为 view 的 toppadding 值,那么设置它为

(320 /1.8 = 1.77)

meterView.setPadding((int) (width/1.8), (int) (height/10), 3, 5);

试试这个。

【讨论】:

    【解决方案3】:

    问题是随着设备尺寸的增加,您的图像尺寸会减小。 相应地重新调整图像大小(增加 mdp 和 ldpi 图像的大小)。 如果你想针对 Nexus 系列,它总是针对 Xhdpi 和 hdpi,这是一个真正的痛苦。 你也可以在这里参考我的回答: Android: support multiple screens

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-22
    • 2023-03-10
    相关资源
    最近更新 更多