andriod表格布局

表格布局规则:

1:若直接往TableLayout中添加组件,那么这个组件将占满一行

2:若想一行上有多个组件的话,就要添加一个TableRow的容器,把组件都放到里面

      tablerow中的组件个数就决定了该行有多少列

      列的宽度由该列中最宽的单元格决定

3:整个表格布局的宽度取决于父容器的宽度(占满父容器本身)

常用的属性:

1:android:collapseColumns:设置需要被隐藏的列的序号

2:android:shrinkColumns:设置允许被收缩的列的列序号

3:android:stretchColumns:设置运行被拉伸的列的列序号

4.TableLayout的局部属性(内部控件所用属性) 

android:layout_column=”1” 该控件显示在第1列 

android:layout_span=”2” 该控件占据两列

隐藏第一列和第三列(从零开始)

<TableLayout
    android:id="@+id/ws1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:collapseColumns="0,2" >
    <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="第三块" />
        <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>

 

                                                       

 

 

设置第二列为可拉伸列,让该列填满这一行所有的剩余空间

<TableLayout
    android:id="@+id/ws1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="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>

                                                                

设置第二列为可收缩列

<TableLayout
    android:id="@+id/ws1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:shrinkColumns="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>

                                                     

 

uploading.gif转存失败重新上传取消uploading.gif转存失败重新上传取消

 

指定列的时候如果组件前没有其他空间 将显示空白

<TableLayout
    android:id="@+id/ws1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     >
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:text="在tablerow外独占一行" />
    <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:layout_column="2"
            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>
    <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:layout_span="2"
            android:text="第六块" />


    </TableRow>
</TableLayout>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值