Android TableLayout 表格佈局

TableLayout繼承LinearLayout
有多少個TableRow對象就有多少行,
列數等於最多子控件的TableRow的列數
直接在TableLayout加控件,控件會佔據一行
TableLayout屬性(也叫全局屬性):*表明全部列android

android:shrinkColumns -------設置可收縮的列,(內容過多,則收縮,擴展到第二行,控件沒佈滿TableLayout時不起做用)spa

android:stretchColumns ------設置可伸展的列,(有空白則填充)code

列能夠同時具有stretchColumns及shrinkColumns屬性xml

android:collapseColumns ------設置要隱藏的列(索引列從0開始)對象

內部控件屬性:繼承

android:layout_column -------該單元格在第幾列顯示索引

android:layout_span -------該單元格佔據列數,默認爲1utf-8

伸展收縮實例:io

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <!-- 表格1-伸展 -->

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ff0000"
        android:shrinkColumns="0,1,2" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="我佔據一行" />

        <TableRow>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="000000000000000000000000" >
            </Button>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="111111111111111111111111" >
            </Button>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="222222222222222222222222" >
            </Button>
        </TableRow>

        <TableRow>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="000000000000000000000000" >
            </Button>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="2"
                android:text="我佔據2列" >
            </Button>
        </TableRow>
    </TableLayout>

    <!-- 表格2-收縮 -->

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFCD6B"
        android:stretchColumns="0,1" >

        <TableRow>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="填充一" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="填充二" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="普通三" />
        </TableRow>
    </TableLayout>

</LinearLayout>
相關文章
相關標籤/搜索