您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> 安卓开发 >> 正文

android表格布局的使用推荐

作者:佚名    责任编辑:admin    更新时间:2022-06-22

这是一篇关于android表格布局的使用的文章,下面是精品为您提供的内容,希望对您有所帮助

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开始计算)

示例:

< TableLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:id="@+id/button1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Button1" />

android:id="@+id/button2"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Button2" />

android:id="@+id/button3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Button3" />

android:id="@+id/button4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Button4" />

android:layout_height="2dip"

android:background="#FF909090" />

android:id="@+id/button5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Button5" />

android:id="@+id/button6"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Button6" />

android:id="@+id/button7"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Button7" />

android:id="@+id/button8"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Button8" />

以上是小编为您提供的关于android表格布局的使用的内容希望对您有所帮助