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...

  • 相关阅读:
    sql 查出一张表中重复的所有记录数据
    几种常见SQL分页方式效率比较
    Redis命令参考之复制(Replication)
    Redis-benchmark使用总结
    redis压力测试详解
    c#:ThreadPool实现并行分析,并实现线程同步结束
    C#多线程学习 之 线程池[ThreadPool]
    [C#基础]ref和out的区别
    C#:ref和out的联系及区别。
    生产环境中使用Docker Swarm的一些建议
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3151215.html
Copyright © 2011-2022 走看看