android 的tablelayout

TableLayout(表格布局)

TbaleLayout的一些属性;

    xml                             相关用法                            说明

android:collapseColumns     setColumnsCollapsed(in,boolean)   设置需要隐藏的列的序号,多个用逗号隔

android:shrinkColumns       setShrinkColumns(boolean)         设置需要收缩的列的序号,多个用逗号隔

android:stretchColumns      setStretchAllColumns(boolean)     设置需要伸张的列的序号,多个用逗号隔

说明:收缩和伸张的属性可以同时使用,stretchColumns是将父控件填满

      属性值是从0开始,0代表第一列

      行数和列数的确定:是通过TableRow以及其他组件控制表格的行数和列数,具体如下:

      TableLayout的行数有开发人员制定,即有多少个TableRow对象(或view控件),就有多少行

      列的宽度:又该列中最宽的单元格决定,整个表格布局的宽度取决于父容器的宽度(默认是占满父容器本身)  如第一个TableRow含2个控件,第二个TableRow含3个控件,那么该TableRow的列数为3

单元格属性,2个参数

      android:layout_column        指定单元格在第几列显示

      android:layout_span          指定单元格占的列数(未指定时 为1)

      且一个空间也可以同时具备这两个特性

                                                                                   android:collapse=“1”因此该TableLayout里的TableRow的列1,即第二列(从0开始计算)

 

 

示例:

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

    <TableRow >

        <Button
            android:id="@+id/button1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button1" />
    </TableRow>

    <TableRow >

        <Button
            android:id="@+id/button2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button2" />
    </TableRow>

    <TableRow >

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button3" />
    </TableRow>

    <TableRow >

        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button4" />
    </TableRow>

    <View
        android:layout_height="2dip"
        android:background="#FF909090" />

    <TableRow >

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

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

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

        <Button
            android:id="@+id/button8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button8" />
    </TableRow>

</TableLayout>

 

效果图:

android的表格布局
     

示例2

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="0,1,2"   >

    <TableRow>
     <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1"
        android:layout_column="0"  /> 

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

        android:layout_column="1" />
     </TableRow>
      <TableRow>                                                      
       <Button 
         android:id="@+id/button3"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Button3" 
         android:layout_column="1"   />
       <Button 
         android:id="@+id/button4"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Button4" 
         android:layout_column="1"   />
        </TableRow>
        <TableRow>
          <Button      

          android:id="@+id/button5"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Button5"
          android:layout_column="2"   />
         </TableRow>
</TableLayout>

效果图;


android的表格布局





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值