2
我卡在可能很簡單的東西,但我似乎無法弄清楚。我正在尋找的一個例子是一個帶有4個按鈕的屏幕。一個取整個左上象限,第二個取整個右上象限,第三個取整個左下象限,第四個取整個右下象限。最終結果將是4個按鈕填滿整個屏幕。Android佈局等寬和高度
我似乎能夠同樣拉伸物體來填充屏幕的寬度,或者我可以拉伸物體來填充高度。我似乎無法弄清楚的是如何同時拉伸寬度和高度。
任何幫助,這將不勝感激。
我卡在可能很簡單的東西,但我似乎無法弄清楚。我正在尋找的一個例子是一個帶有4個按鈕的屏幕。一個取整個左上象限,第二個取整個右上象限,第三個取整個左下象限,第四個取整個右下象限。最終結果將是4個按鈕填滿整個屏幕。Android佈局等寬和高度
我似乎能夠同樣拉伸物體來填充屏幕的寬度,或者我可以拉伸物體來填充高度。我似乎無法弄清楚的是如何同時拉伸寬度和高度。
任何幫助,這將不勝感激。
我想你正試圖用一個LinearLayout來做到這一點。我可能會使用兩個LinearLayouts來處理它。例如:
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1">
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1">
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
剛剛測試過,它絕對有效。 LINT表示嵌套權重對性能不利,但它絕對具有正確的佈局。