標籤:
一、TableLayout概述
TableLayout表格版面配置模型以行列的形式管理子控制項,每一行為一個TableRow的對象,當然也可以是一個View的對象
二、TableLayout的全域屬性
1、android:collapseColumns = "1,2"
隱藏從0開始索引列,列直接必須ongoing逗號隔開:1,2,5
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:collapseColumns="0" > <TableRow android:id="@+id/tableRow1" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一個按鈕" android:id="@+id/button" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第二個按鈕" android:id="@+id/button2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第三個按鈕" android:id="@+id/button3" /> </TableRow></TableLayout>
2、android:shrikColumns = "1,2"
收縮從0開始的索引列。當可收縮的列太寬(內容過多)不會被擠出螢幕,列直接必須用逗號隔開:1,2,5,你可以通過"*"代替收縮所有列。注意一列能同時表示收縮和展開。
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:shrinkColumns="2" > <TableRow android:id="@+id/tableRow1" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一個按鈕" android:id="@+id/button" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第二個按鈕" android:id="@+id/button2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第三個按鈕大神快放假了凱撒的解放路卡手機的路口發生的積分卡拉斯加" android:id="@+id/button3" /> </TableRow></TableLayout>
3、android:stretchColumns = "1,2"
展開從0開始的索引列。以填滿剩下的多餘空白控制項,列直接必須用逗號隔開:1,2,3,可以通過"*"代替收縮所有列。注意一列能同時表示收縮和展開。
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="2" > <TableRow android:id="@+id/tableRow1" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一個按鈕" android:id="@+id/button" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第二個按鈕" android:id="@+id/button2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第三個按鈕" android:id="@+id/button3" /> </TableRow></TableLayout>
三、TableLayout的局部屬性(內部控制項所有屬性)
1、android:layout_column = "1" 該控制項顯示在第二列
2、android:layout_span = "2" 該控制項佔據2列
四、實現簡單的計算機布局
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="*" android:shrinkColumns="*"> <TextView android:gravity="right|center" android:layout_width="fill_parent" android:layout_height="40" android:text="90" android:id="@+id/textView" /> <TableRow android:id="@+id/tableRow1" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="7" android:id="@+id/button" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="8" android:id="@+id/button2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="9" android:id="@+id/button3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="/" android:id="@+id/button4" /> </TableRow> <TableRow android:id="@+id/tableRow2" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="4" android:id="@+id/button5" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="6" android:id="@+id/button6" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="7" android:id="@+id/button7" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="*" android:id="@+id/button8" /> </TableRow></TableLayout>
Android布局_表格版面配置TableLayout