一、TableLayout的概述
????????表格布局是以行數(shù)和列數(shù)來(lái)確定位置進(jìn)行排列。就像一間教室,確定好行數(shù)與列數(shù)就能讓同學(xué)有序入座。
注意:我們需要先添加<TableRow
容器,每添加一個(gè)就會(huì)多一行,然后再往<TableRow
容器中添加其它組件。
二、TableLayout的屬性
? ? 2.1 、TableLayout(表格布局)的樣式,就像是一張表格。每個(gè)TableLayout,都由多個(gè)TableRow組成,每個(gè)TableRow就是一行,有幾個(gè)TableRow就有幾行。TableLayout不會(huì)顯示行號(hào)和列號(hào),也沒(méi)有分割線,其行數(shù)和列數(shù)都可以進(jìn)行操作。
????????下面是 3 (行) x 3(列) 的TableLayout基本使用,其xml布局文件table_layout.xml如下:
<?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"> <TableRow> <Button android:id="@+id/button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按鈕1" /> <Button android:id="@+id/button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按鈕2" /> <Button android:id="@+id/button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按鈕3" /> </TableRow> <TableRow> <Button android:id="@+id/button04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按鈕4" /> <Button android:id="@+id/button05" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按鈕5" /> <Button android:id="@+id/button06" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按鈕6" /> </TableRow> <TableRow> <Button android:id="@+id/button07" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按鈕7" /> <Button android:id="@+id/button08" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按鈕8" /> <Button android:id="@+id/button09" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按鈕9" /> </TableRow> </TableLayout>
效果圖:
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-424510.html
?2.2 、TableLayout的android:shrinkColumns屬性,當(dāng)TableRow里邊的空間布滿布局的時(shí)候,指定列自動(dòng)文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-424510.html
到了這里,關(guān)于Android 基礎(chǔ)知識(shí)4-2.8 TableLayout(表格布局)詳解的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!