【问题标题】:Android support multi screens issue on real devicesAndroid 在真机上支持多屏问题
【发布时间】:2014-07-09 17:42:02
【问题描述】:

我正在 Android 中创建一个应该支持多屏幕的应用,并且我已经实现了支持多屏幕的技术,如下所示: - 为 small、normal、large 和 xlarge 创建布局文件夹 - 为 drawable-hdpi、drawable-ldpi、drawable-mdpi 和 drawable-xhdpi 提供图像 - 在应用清单中添加了以下代码:

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

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="17" />

并已调整布局编辑器输入,如下图所示

问题是这些布局在真实设备上无法正常工作,并且有 元素或大或小,其边距有时比布局编辑器预览更大或更小

布局示例

    <Button
        android:id="@+id/btn_refresh"
        android:layout_width="35dp"
        android:layout_height="50dp"
        android:layout_marginLeft="60dp"
        android:background="@color/transparent"
        android:onClick="refreshBtnAction" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="280dp"
        android:layout_marginTop="85dp"
        android:layout_marginRight="19dp"
        android:layout_marginLeft="15dp"
        android:divider="#E9CE9A"
        android:fadingEdge="none"
        android:dividerHeight="1dp" />

</RelativeLayout>

如果您能解释我应该做些什么来确保布局在真实设备上正常工作,我将不胜感激 在此先感谢

【问题讨论】:

  • 如果您无法访问您想在其上进行测试的所有设备,Google 会提供一项服务,让人们在 Beta 版中测试您的应用,并让您知道它的运行情况。
  • 非常感谢@durbnpoisn,我将在接下来的测试中使用它

标签: android layout


【解决方案1】:

我发现最好使用 sp 而不是 dp 并且尽可能使用预定义的宽度和高度。我的意思是像 android:layoutWidth="match_parent" 和使用 LayoutWeigt。下面是一个让 2 个按钮始终为 80% 和 20% 的示例,无论屏幕分辨率是多少(参见属性 weightSum 和 layout_weight):

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="100"
    >


    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bResults"
        android:text="Try Command"
        android:layout_weight="20" />

    <ToggleButton
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tbPassword"
        android:layout_weight="80"
        android:checked="true"
        />

</LinearLayout>

这样您就不需要任何“布局文件夹”,只需要不同图像分辨率的文件夹。我不确定您使用什么编辑器,但使用 Android Studio 或 Eclipse,这些文件夹通常会自动构建。在你有“dp”的地方写下“sp”,这也有帮助。在使用给定的建议时,我从来没有遇到过这个问题。我的应用在 3.7 英寸上的外观与 Nexus 10 上的外观相同。

【讨论】:

  • 非常感谢@Senchay,它对我不起作用,仍然有同样的问题
猜你喜欢
  • 2014-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多