我是Android新手,所以不太擅長GUI佈局。我正在爲我的應用程序構建一個GUI,但無法讓它按照我想要的方式行事。我需要的是屏幕底部水平堆疊的4個按鈕。在按鈕上方放置了一個SurfaceView,我想填充屏幕的其餘部分。結果應該是這樣的(我希望這是明確的):
Android - 圖形用戶界面佈局
-----------------
- -
- -
- -
- -
- SurfaceView -
- -
- -
- -
-----------------
--- --- --- ---
-B- -B- -B- -B-
--- --- --- ---
我得到的closeset是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<SurfaceView
android:id="@+id/surfaceView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Button" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Button" />
</LinearLayout>
</TableRow>
</TableLayout>
</LinearLayout>
不幸的結果是這樣的:
-----------------
- SurfaceView -
-----------------
--- --- --- ---
-B- -B- -B- -B-
--- --- --- ---
謝謝,這工作。只要網站允許,我會盡快接受。你可以請解釋你如何使用這些屬性:android:layout_height =「0dp」 android:layout_weight =「1」 – Yoav
檢查我編輯的答案。 –
再次感謝 – Yoav