android标签table,详解Android TableLayout表格布局

表格布局的标签是TableLayout,TableLayout继承了LinearLayout。所以它依然是一个线性布局。

前言:

1、TableLayout简介

2、TableLayout行列数的确定

3、TableLayout可设置的属性详解

4、一个包含4个TableLayout布局的实例及效果图

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="3dip"

>

android:text="数字键盘"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:textSize="20sp"

android:background="#7f00ffff"/>

android:id="@+id/table2"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:padding="1dip">

一、Tablelayout简介

Tablelayout类以行和列的形式对控件进行管理,每一行为一个TableRow对象,或一个View控件。

当为TableRow对象时,可在TableRow下添加子控件,默认情况下,每个子控件占据一列。

当为View时,该View将独占一行。

二、TableLayout行列数的确定

TableLayout的行数由开发人员直接指定,即有多少个TableRow对象(或View控件),就有多少行。

TableLayout的列数等于含有最多子控件的TableRow的列数。如第一TableRow含2个子控件,第二个TableRow含3个,第三个TableRow含4个,那么该TableLayout的列数为4.

三、TableLayout可设置的属性详解

TableLayout可设置的属性包括全局属性及单元格属性。

1、全局属性也即列属性,有以下3个参数:

android:stretchColumns 设置可伸展的列。该列可以向行方向伸展,最多可占据一整行。

android:shrinkColumns 设置可收缩的列。当该列子控件的内容太多,已经挤满所在行,那么该子控件的内容将往列方向显示。

android:collapseColumns 设置要隐藏的列。

示例:

android:stretchColumns="0" 第0列可伸展

android:shrinkColumns="1,2" 第1,2列皆可收缩

android:collapseColumns="*" 隐藏所有行

说明:列可以同时具备stretchColumns及shrinkColumns属性,若此,那么当该列的内容N多时,将“多行”显示其内容。(这里不是真正的多行,而是系统根据需要自动调节该行的layout_height)

2、单元格属性,有以下2个参数:

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

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

示例:

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

android:layout_span="2" 该控件占据2列

说明:一个控件也可以同时具备这两个特性。

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="3dip"

>

android:text="表1:全局设置:列属性设置"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:textSize="15sp"

android:background="#7f00ffff"/>

android:id="@+id/table1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:stretchColumns="0"

android:shrinkColumns="1"

android:collapseColumns="2"

android:padding="3dip">

android:text="表2:单元格设置:指定单元格属性设置"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:textSize="15sp"

android:background="#7f00ffff"/>

android:id="@+id/table2"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:padding="3dip">

android:text="我跨1到2列,不信你看!"

android:layout_column="1"

android:layout_span="2"

/>

android:text="表3:应用一,非均匀布局"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:textSize="15sp"

android:background="#7f00ffff"/>

android:id="@+id/table3"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:stretchColumns="*"

android:padding="3dip"

>

android:text="表4:应用二,均匀布局"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:textSize="15sp"

android:background="#7f00ffff"/>

android:id="@+id/table4"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:stretchColumns="*"

android:padding="3dip"

>

android:text="表5:应用三,均匀布局"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:textSize="15sp"

android:background="#7f00ffff"/>

android:id="@+id/table5"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:stretchColumns="*"

android:padding="6dip"

>

style="?android:attr/buttonStyleSmall"

android:layout_width="1dip"

android:layout_height="wrap_content"

android:text="New Button"

android:id="@+id/button" />

以上内容是小逼给大家介绍的Android TableLayout表格布局,希望对大家有所帮助!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值