【问题标题】:How to keep this layout uniform across screen sizes如何在不同的屏幕尺寸上保持这种布局一致
【发布时间】:2011-07-17 09:55:41
【问题描述】:

我想进行以下布局,请参见下图,其中 EditText 视图的位置保持正确位置 w.r.t。箭头。

下面的布局是我使用页边距使用 RelativeLayout 制作的,但是当有人将此应用程序安装在 540x960 分辨率的手机上(如 HTC 感觉)时,这将不起作用。

提前感谢您的帮助!

Valid XHTML http://www.tricky.dds.nl/gui.png.

【问题讨论】:

    标签: android layout screen-resolution uniform


    【解决方案1】:

    使用 LinearLayout 和 RelativeLayout 的组合。使用 LinearLayout,您可以在屏幕上创建与所有设备完全相同的空间。让您的顶级容器成为 LinearLayout。例如,要在您引用的图像中创建第二行,请执行以下操作:

    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="horizontal">
    
    <RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1">
    
    </RelativeLayout>
    
    <RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1">
    
    <TextView
    android:layout_width="wrap_content"
      android:layout_height="wrap_content"
    android:layout_centerInParent="true">
    </TextView>
    
    </RelativeLayout>
    
    <RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1">
    
    </RelativeLayout>
    
    <RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1">
    
    <TextView
    android:layout_width="wrap_content"
      android:layout_height="wrap_content"
    android:layout_centerInParent="true">
    </TextView>
    
    </RelativeLayout>
    
    <RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1">
    
    </RelativeLayout>
    
    </LinearLayout>
    

    【讨论】:

    • 您好,Emiam,感谢您的回答。我已经按照您的建议实施了,但是上面的答案仍然没有解决一件事。我制作了一张图片来比较不同的分辨率:tricky.dds.nl/540x960vs480x800.png 在这里您可以看到存储在 HDPI 中的背景与两种分辨率都不匹配。我应该根据分辨率加载不同的背景图像还是可以通过布局修复?再次感谢!
    • 我了解您的问题。你使用什么组件?文本视图?根据我的经验,如果您正在处理图像视图,这可以通过布局来解决。您是否同时使用垂直和水平线性布局?这使您能够创建可以放置组件的“盒子”。还要确保对所有线性布局父级使用“android:weighSum”。
    • 我只使用 EditTexts 和 Textviews。我使用两个 LinearLayout,一个用于垂直布局,一个用于每一行。该图像只是覆盖在两种分辨率下使用的整个背景(480x7xx)的背景,因此有两种 HDPI 布局。将我的图像切片并将这些背景的块切片作为背景图像会更好吗?非常感谢您抽出时间提供帮助!
    • 虽然这是一个肮脏的黑客,是的,你可以这样做。更好的做法是保留背景颜色并切分线条。祝你好运!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多