我是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