Android佈局--TableLayout

TableLayout表格佈局以行列的形式管理子控件,每一行爲一個TableRow的對象,固然也能夠是一個View的對象。android

1、TableLayout的全局屬性

android:collapseColumns="1,2"   --隱藏從0開始的索引列,列直接、必須用逗號隔開:1,2,5

android:shrinkColumns="1,2"    --收縮從0開始的索引列,當可收縮的列太寬(內容過多)不會被擠出屏幕,列直接必須用逗號隔開:1,2,5,你能夠用"*"代替收縮全部列。注意一列能同時表示收縮和拉伸。

android:stretchColumns="1,2"    --拉伸從0開始的索引列,以填滿剩下的多餘空白空間,列直接必須用逗號隔開:1,2,3,你能夠用"*"代替收縮全部列。注意一列能同時表示收縮和拉伸。

1.android:collapseColumns佈局

實例:spa

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"
    android:layout_width="match_parent" android:layout_height="match_parent"
    tools:context="com.example.demo4.MainActivity">


    <TableRow
        android:id="@+id/row1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
            android:text="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button" />

        <Button
            android:text="2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button2" />

        <Button
            android:text="3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button3" />
    </TableRow>
</TableLayout>

界面以下:code

添加TableLayout中添加屬性:xml

android:collapseColumns="0"

結果是將第0列隱藏了對象

2.android:stretchColumns索引

添加:utf-8

android:stretchColumns="2"

3.android:shrinkColumnsit

加長button3的文字:io

在屬性中添加:

android:shrinkColumns="2"

能夠看到收縮效果:

2、TableLayout的局部屬性(內部控件所用屬性)

android:layout_column="1"  --該控件顯示在第2列
android:layout_span="2"    --該控件佔據2列