帮助布局类型

时间:2011-09-26 11:42:48

标签: java android layout

我应该将这种布局用于这样的布局? enter image description here

我应该使用线性布局还是相对?你能解释一下为什么选择你做的布局吗?样本也会有所帮助。

由于

2 个答案:

答案 0 :(得分:1)

如果您的布局如上所示简单,我会使用LinearLayout - 主要是因为我觉得使用相对布局有点烦人且更难找到错误。

样本将是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_height="wrap_content"
    android:layout_width="fill_parent" android:id="@+id/linearLayout1"
    android:orientation="vertical" android:layout_weight="1"
    android:background="@android:color/darker_gray">
         <!-- Put widgets here -->
    </LinearLayout>
    <LinearLayout android:layout_height="100dp"
    android:layout_width="fill_parent" android:id="@+id/linearLayout2"
    android:orientation="vertical" android:background="@android:color/background_light">
         <!-- Put widgets here -->
    </LinearLayout>
</LinearLayout>

答案 1 :(得分:1)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
    <RelativeLayout android:layout_width="match_parent"
        android:background="#ff00" android:id="@+id/relativeLayout1"
        android:layout_height="100dp" android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"></RelativeLayout>
    <RelativeLayout android:layout_width="match_parent"
        android:background="#f0f0" android:id="@+id/relativeLayout2"
        android:layout_height="wrap_content" android:layout_alignParentTop="true"
        android:layout_above="@+id/relativeLayout1"
        android:layout_centerHorizontal="true"></RelativeLayout>
</RelativeLayout>
相关问题