zoukankan      html  css  js  c++  java
  • Android 表格布局<TableLayout>

     表格布局即,tableLayout,表格布局通过行、列的形式来管理UI组件,TablelLayout并不需要明确地声明包含多少行、多少列,而是通过TableRow,以及其他组件来控制表格的行数和列数,
        TableRow也是容器,因此可以向TableRow里面添加其他组件,没添加一个组件该表格就增加一列。
        如果想TableLayout里面添加组件,那么该组件就直接占用一行。
    在表格布局中,列的宽度由该列中最宽的单元格决定,整个表格布局的宽度取决于父容器的宽度(默认是占满父容器本身)。
    TableLayout继承了LinearLayout,因此他完全可以支持LinearLayout所支持的全部XML属性,除此之外TableLayout还支持以下属性:
    XML属性                                                 相关用法                                                    说明
    1. andriod:collapseColumns           setColumnsCollapsed(int ,boolean)       设置需要隐藏的列的序列号,多个用逗号隔开
    2.android:shrinkColumns              setShrinkAllColumns(boolean)                 设置被收缩的列的序列号,多个用逗号隔开
    3.android:stretchColimns             setSretchAllColumnds(boolean)               设置允许被拉伸的列的序列号,多个用逗号隔开
     
    代码如下所示:
     <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="
    http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
          >
      <!-- 定义第一个表格布局,指定第二列允许收缩,第三列允许拉伸 -->
      <TableLayout 
     android:id="@+id/tablelayout1"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:shrinkColumns="1"
     android:stretchColumns="2"
     >
     <!-- 直接添加一个button,他自己会占用一行 -->
     <Button
    android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="独自占用一行的按钮"/>
     <!-- 先添加一个tableRow,在添加三个button, 结果应该是三个button在这个tableRow(行)里面,即排列为一行 -->
     <TableRow >
     <Button android:layout_width="wrap_content"
     android:layout_height="wrap_content"
    android:text="RBtn1"/>
     <Button
     android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="RBtn2"/>
     <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:text="RBtn3"/>
    </TableRow>
     </TableLayout>
     </LinearLayout>
    上面代码展示了,在tableLayour中使用TableRow的效果,和不使用TableRow的效果,并第二列允许收缩,第三列允许拉伸。运行结果如下所示:
     
    下面说明XML属性的隐藏使用方法,在TableLayout中添加一下代码,
     
    android:collapseColumns="0"
    代码如下所示:
     
    注意:属性中设置列号的时候是从0,1,2,3 ....
             不是1,2,3...

  • 相关阅读:
    刘翔那点事
    网站建站模板
    搞笑!from 饮水思源
    我de虚拟经济学系列第一章 经济危机拼命建桥
    IT民工系列——c#操作Microsoft IE,实现自动登录吧!
    商业智能的发展及其应用
    我de虚拟经济学系列第三章 常见的致富之路
    IT民工系列——c#操作EditGrid,自己做一个在线Excel数据库吧!
    Asp.net下的Singleton模式
    asp.net 控件功能小结
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3151215.html
Copyright © 2011-2022 走看看