我想創建一個可重用的表格佈局,其中我有3行,最後一行僅包含1個元素,而前兩個包含2個元素。表格佈局中的等高行
現在,問題是,儘管對每一行賦予相同的權重,但表格佈局中的行並不具有相同的高度。 底排消耗太多空間。
以下是佈局內容:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="3"
>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="2" >
<TextView
android:id="@+id/txtvw_age"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/age" >
</TextView>
<TextView
android:id="@+id/txtvw_roll_no"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/roll_no" >
</TextView>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="2" >
<TextView
android:id="@+id/txtvw_standard"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/standard" >
</TextView>
<TextView
android:id="@+id/txtvw_section"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/section" >
</TextView>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<TextView
android:id="@+id/txtvw_ct_name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="@string/ct_name" >
</TextView>
</TableRow>
</TableLayout>
「TableRow」的任何高度和寬度設置都被忽略,並且'TableLayout'自動將'fill_parent'設置爲'layout_width'和'wrap_content'設置爲'layout_height' –