2012-02-16 63 views
3

我有一個大約3行的TableLayout。我希望獲得最後一行的高度來填充視圖的其餘部分,但沒有太多運氣(因爲使用Android佈局是徒勞無益的一課)。這是我到目前爲止有:展開TableLayout的最後一行

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:stretchColumns="*" > 

    <TableRow android:padding="5dip"> 
      <TextView 
      android:text="Row 1" 
      /> 
    </TableRow> 
    <TableRow android:padding="5dip"> 
     <TextView 
      android:text="Row 2" 
      /> 
    </TableRow> 
    <TableRow android:padding="5dip" android:layout_height="fill_parent"> 
     <TextView 
      android:text="Row 3" 
      /> 
    </TableRow> 
</TableLayout> 

回答

1

只需使用更簡單的LinearLayout。以下0dp是故意的。

<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="wrap_content" android:padding="5dip" android:orientation="horizontal"> 
      <TextView 
      android:text="Row 1" 
      /> 
    </LinearLayout> 
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5dip" android:orientation="horizontal"> 
     <TextView 
      android:text="Row 2" 
      /> 
    </LinearLayout> 
    <LinearLayout android:layout_width="fill_parent" android:padding="5dip" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal"> 
     <TextView 
      android:text="Row 3" 
      /> 
    </LinearLayout> 
</LinearLayout> 
0

你有沒有嘗試設置其他兩行的佈局高度或將其設置爲包裹內容和最後一個作爲填充母?

2

Sollution:

對於你在佈局中使用的重量。

請參見下面的XML代碼:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    > 

    <TableRow android:padding="5dip"> 
     <TextView android:text="Row 1" /> 
    </TableRow> 
    <TableRow android:padding="5dip"> 
     <TextView android:text="Row 2" /> 
    </TableRow> 
    <TableRow android:padding="5dip" android:layout_weight="1"> 
     <TextView android:text="Row 3" /> 
    </TableRow> 
</TableLayout> 

享受。 :)

+0

這應該被標記爲正確答案 – 2014-09-24 09:57:36

+0

感謝@RaduSimionescu的評論。 – 2014-09-24 11:47:59