如何在屏幕尺寸上保持此布局统一

时间:2011-07-17 09:55:42

标签: android layout screen-resolution uniform

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

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

提前感谢您的帮助!

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

1 个答案:

答案 0 :(得分: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>
相关问题