我想創建以下佈局。Android:佈局與中間組件展開
+---------------------+
| Text View |
+---------------------+
| |
| |
| Custom View |
| Expands to |
| extra space |
| |
+---------------------+
|Button1 |Button2 |
+---------------------+
我的佈局xml如下所示。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="This is test text." android:id="@+id/statusTxt"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/gameView"
android:layout_gravity="bottom">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/gameButtonView">
<Button android:text="Done" android:id="@+id/doneBtn"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="Undo" android:id="@+id/undoBtn"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
</LinearLayout>
</LinearLayout>
比編程我加入我的自定義視圖
LinearLayout gameView = (LinearLayout)this.findViewById(R.id.gameView);
gameView.addView(gameBoardView, 1);
隨着當前佈局它結束了看起來像這樣。
+---------------------+
| Text View |
+---------------------+
|Button1 |Button2 |
+---------------------+
| |
| |
| Custom View |
| Expands to |
| extra space |
| |
+---------------------+
當前的佈局所做的是將最下面的按鈕粘到自定義視圖上方。關於如何讓它呈現我如何描述的任何想法?
你能不能只需在中間的LinearLayout中取出android:layout_gravity =「bottom」? – brianestey