【问题标题】:Making android support all screen sizes使android支持所有屏幕尺寸
【发布时间】:2014-02-19 19:48:45
【问题描述】:

我觉得我是唯一一个在这里迷路的人。似乎每个人都可以使用 DP 使应用程序在多种屏幕尺寸上运行。对我来说,每当我加载另一个屏幕时,对齐永远不会是正确的比例。

但是,如果我使用 android:weight 一切都将在所有设备上正常扩展。我对所有内容的 android weight 的问题是它并不总是想将图像调整到布局中,更不用说使用嵌套权重会得到的警告了。

我看到的一个解决方案是为每个可能的屏幕尺寸创建一个新的屏幕尺寸。这是其他人都做的吗?起初我以为我们只需要创建 x-large、small 等布局,结果发现即使这些布局也无法适应各种屏幕尺寸(即使 nexus 7 也不属于这些类别中的任何一个) .

示例代码

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="50"
    android:background="@drawable/layout_border"
    android:padding="10dp" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="160dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:contentDescription="@string/app_name"
        android:src="@drawable/yg" />

            <ProgressBar
                android:id="@+id/progressBar2"
                style="@android:style/Widget.ProgressBar.Horizontal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/imageView1"
                android:layout_alignParentRight="true"
                android:layout_toRightOf="@+id/imageView1"
                android:paddingBottom="10dp"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:progress="50" />

            <TextView
                android:id="@+id/textView1"
                style="@style/NormalFont"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/progressBar2"
                android:layout_alignLeft="@+id/progressBar2"
                android:layout_marginLeft="36dp"
                android:text="@string/exercise_percent" />

            <ImageButton
                android:id="@+id/imageButton1"
                android:layout_width="100dip"
                android:layout_height="100dip"
                android:layout_above="@+id/textView1"
                android:layout_toRightOf="@+id/imageView1"
                android:adjustViewBounds="true"
                android:contentDescription="@string/app_name"
                android:background="@drawable/start"
                android:onClick="meditateTask" />



</RelativeLayout>

例如,这里的图像按钮在每个新的屏幕尺寸上都会不合适。

【问题讨论】:

  • 您能否提供示例布局并描述您在每个布局中遇到的问题?
  • 添加了一个似乎不想正确对齐的示例布局。
  • android:layout_weight 用于一次按比例缩放一个维度(例如,以 % 表示)。嵌套权重不利于性能。除此之外,您还可以使用 9 Patchesdp(与设备无关的像素)以及带有临时图形的老式 drawable 和 values 文件夹和尺寸。 TABLETS 属于另一类 drawables/values 文件夹。

标签: android android-layout


【解决方案1】:

您可以为所有屏幕尺寸(小、正常、大和 x 大)创建相同的布局。 如何做到这一点:在布局文件夹中创建新的 XML 布局文件,使其与要修改的布局具有相同的名称以适应所有屏幕尺寸。单击下一步,将显示一些选项,找到大小并插入它。然后,您将能够选择所需的屏幕尺寸。 启动时,系统将为设备选择最佳屏幕尺寸。 对所有 4 种屏幕尺寸重复此操作。希望这会有所帮助

【讨论】:

  • 正如我所说,仅创建 4 个文件夹不足以处理所有可能的大小。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多