以下是我的代碼。我想要一個界面,我有一個單行文本框,一個多行文本框,下面有兩個按鈕。我希望多行文本框在渲染按鈕和文本框後佔用所有可用空間。爲此,我在主佈局中創建了兩個LinearLayouts。第一個垂直方向的layout_width設置爲fill_parent。第二個是水平的fill_parent。Android - 線性佈局排列,未按預期定位
第一個有一個文本框,我已將layout_height設置爲填充父項。第二個有兩個文本框確定並取消。
當我運行這個應用程序,我得到的用戶界面,但按鈕是非常小(約5px的高度)。我必須手動設置按鈕高度。我在這裏做錯了什麼。我不想硬編碼按鈕高度。
<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:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1">
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Name"></TextView>
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content"></EditText>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Contents"></TextView>
<EditText android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="top" />
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1">
<Button android:id="@+id/okbutt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="OK" android:layout_weight="1" />
<Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="Cancel" android:layout_weight="1" />
</LinearLayout>
感謝, 阿倫
感謝svdree,您的解決方案的工作原理。仍然想知道爲什麼我沒有。 – Arun 2010-12-23 13:57:16