表格布局模型以行列的形式管理子控件,每一行为一个TableRow的对象,当然也可以是一个View的对象。TableRow可以添加子控件,每添加一个为一列。

TableLayout属性:

  android:collapseColumns:将TableLayout里面指定的列隐藏,若有多列需要隐藏,请用逗号将需要隐藏的列序号隔开。

  android:stretchColumns:设置指定的列为可伸展的列,以填满剩下的多余空白空间,若有多列需要设置为可伸展,请用逗号将需要伸展的列序号隔开。

  android:shrinkColumns:设置指定的列为可收缩的列。当可收缩的列太宽(内容过多)不会被挤出屏幕。当需要设置多列为可收缩时,将列序号用逗号隔开。

 列元素(Button)属性:(奇怪的是button 里面没有android:layout_column 和android:layout_span两个属性,写进去无反应,还不知道为什么)

  android:layout_colum:设置该控件在TableRow中指定的列

  android:layout_span:设置该控件所跨越的列数

图片:

代码:

  1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:tools="http://schemas.android.com/tools"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical"
6 tools:context=".AndroidTableLayoutActivity" >
7
8 <!-- 定义第一个表格,指定第2列允许收缩,第3列允许拉伸 -->
9
10 <TableLayout
11 android:id="@+id/tablelayout01"
12 android:layout_width="match_parent"
13 android:layout_height="wrap_content"
14 android:shrinkColumns="1"
15 android:stretchColumns="2" >
16
17 <!-- 直接添加按钮,自己占用一行 -->
18
19 <Button
20 android:id="@+id/btn01"
21 android:layout_width="wrap_content"
22 android:layout_height="wrap_content"
23 android:text="独自一行" >
24 </Button>
25
26 <TableRow>
27
28 <Button
29 android:id="@+id/btn02"
30 android:layout_width="wrap_content"
31 android:layout_height="wrap_content"
32 android:text="普通" >
33 </Button>
34
35 <Button
36 android:id="@+id/btn03"
37 android:layout_width="wrap_content"
38 android:layout_height="wrap_content"
39 android:text="允许被收缩允许被收缩允许被收缩允许被收缩" >
40 </Button>
41
42 <Button
43 android:id="@+id/btn04"
44 android:layout_width="wrap_content"
45 android:layout_height="wrap_content"
46 android:text="允许被拉伸" >
47 </Button>
48 </TableRow>
49 </TableLayout>
50 <!-- 定义第2个表格,指定第2列隐藏 -->
51
52 <TableLayout
53 android:id="@+id/tablelayout02"
54 android:layout_width="match_parent"
55 android:layout_height="wrap_content"
56 android:collapseColumns="1" >
57
58 <TableRow>
59
60 <Button
61 android:id="@+id/btn05"
62 android:layout_width="wrap_content"
63 android:layout_height="wrap_content"
64 android:text="普通" >
65 </Button>
66
67 <Button
68 android:id="@+id/btn06"
69 android:layout_width="wrap_content"
70 android:layout_height="wrap_content"
71 android:text="被隐藏列" >
72 </Button>
73
74 <Button
75 android:id="@+id/btn07"
76 android:layout_width="wrap_content"
77 android:layout_height="wrap_content"
78 android:text="允许被拉伸" >
79 </Button>
80 </TableRow>
81 </TableLayout>
82 <!-- 定义第3个表格,指定第2列填满空白-->
83
84 <TableLayout
85 android:id="@+id/tablelayout03"
86 android:layout_width="match_parent"
87 android:layout_height="wrap_content"
88 android:stretchColumns="1"
89 >
90
91 <TableRow>
92
93 <Button
94 android:id="@+id/btn08"
95 android:layout_width="wrap_content"
96 android:layout_height="wrap_content"
97 android:text="普通" >
98 </Button>
99
100 <Button
101 android:id="@+id/btn09"
102 android:layout_width="wrap_content"
103 android:layout_height="wrap_content"
104 android:text="填满剩余空白" >
105 </Button>
106 </TableRow>
107 </TableLayout>
108 <!-- 定义第3个表格,指定第2列横跨2列-->
109
110 <TableLayout
111 android:id="@+id/tablelayout04"
112 android:layout_width="match_parent"
113 android:layout_height="wrap_content"
114 >
115
116 <TableRow>
117
118 <Button
119 android:id="@+id/btn10"
120 android:layout_width="wrap_content"
121 android:layout_height="wrap_content"
122 android:text="普通" >
123 </Button>
124
125 <Button
126 android:id="@+id/btn11"
127 android:layout_column="2"
128 android:layout_width="wrap_content"
129 android:layout_height="wrap_content"
130 android:text="填满剩余空白" >
131 </Button>
132 </TableRow>
133 </TableLayout>
134 </LinearLayout>

TableLayout(表格布局)的更多相关文章

  1. 【转】TableLayout(表格布局)

    转自:http://www.cnblogs.com/zhangs1986/archive/2013/01/17/2864536.html TableLayout(表格布局) 表格布局模型以行列的形式管 ...

  2. Android零基础入门第29节:善用TableLayout表格布局,事半功倍

    原文:Android零基础入门第29节:善用TableLayout表格布局,事半功倍 前面学习了线性布局和相对布局,线性布局虽然方便,但如果遇到控件需要排列整齐的情况就很难达到要求,用相对布局又比较麻 ...

  3. Android布局-TableLayout表格布局

    一.表格布局-TableLayout 1.概念 表格布局采用行列的形式来管理UI的控件.表格布局适合于有规则的布局. TableRow,用来管理行,TableRow中的一个空间占据该行的一列.若不用T ...

  4. 案例:TableLayout表格布局——迷你计算器

    计算器可以常用线性布局(LinearLayout)和表格布局(tableLayout).Gridlayout 今天我用的是表格布局 效果如下: 代码如下: <TableLayout xmlns: ...

  5. 2.2.3 TableLayout(表格布局)

    3.如何确定行数与列数 ①如果我们直接往TableLayout中添加组件的话,那么这个组件将占满一行!!! ②如果我们想一行上有多个组件的话,就要添加一个TableRow的容器,把组件都丢到里面! ③ ...

  6. android的布局-----TableLayout(表格布局)

    学习导图 (1)TableLayout的相关简介 java的swing编程和html中经常会使用到表格,可见表格的应用开发中使用还是比较多的,同样android也为我们提供这样的布局方式. (2)如何 ...

  7. TableLayout表格布局

    1.本节学习路线图 路线图分析: 从上面的路线图,可以看出TableLayout的用法还是很简单的,无非就是确定表格的行数,以及使用 那三个属性来设置每一行中的第某列的元素隐藏,拉伸,或者收缩即可! ...

  8. Android之TableLayout表格布局

    1.相关属性 1.1.常用属性 android:collapseColumns 设置需要被隐藏的列的序列号 android:shrinkColumns 设置允许被收缩的列的序列号 android:st ...

  9. TableLayout表格布局详解

    一.Tablelayout简介 Tablelayout类以行和列的形式对控件进行管理,每一行为一个TableRow对象,或一个View控件.当为TableRow对象时,可在TableRow下添加子控件 ...

随机推荐

  1. Verilog学习笔记简单功能实现(三)...............同步有限状态机

    在Verilog中可以采用多种方法来描述有限状态机最常见的方法就是用always和case语句.如下图所示的状态转移图就表示了一个简单的有限状态机: 图中:图表示了一个四状态的状态机,输入为A和Res ...

  2. php正规则表达式学习笔记(几个常用函数的区别)

    preg_mache()函数和 preg_mache_all()函数的区别: preg_mache()只会匹配规则中的字符一次, preg_mache_all()会匹配符合条件的所有字符! 例子对比: ...

  3. 使用Apache ab进行压力测试(参数说明)

    我们一般会使用Apache自带的ab来对项目进行压力测试,看项目的执行情况如何. 我们可以使用 ab -v 来查看ab的详细参数使用方法. [root@node234 bin]# ./ab -v ab ...

  4. 【python】获取高德地图省市区县列表

    项目中需要用省市区来进行检索,原想高德地图肯定会有API来获得这些数据,结果没有找到,有一个接口好像可以用,但是会附带大量的边界坐标点. 所以就不如自己把高德的省市区列表扒下来,自己写接口来完成这个功 ...

  5. 如果一个游戏上面加一个透明层,js能不能实现 点击透明层的任意点 而正常玩游戏

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. JavaScript中的null与nudefined

    null和undefined 概述 null与undefined都可以表示"没有",含义非常相似.将一个变量赋值为undefined或null,老实说,语法效果几乎没区别. var ...

  7. ASP.NET数据绑定技术

    1.DataBinder.Eval()方法 DataBinder.Eval()方法是ASP.NET框架支持的一个静态方法,用来计算Late_Bound(后期绑定)数据绑定表达式,并随时将结果转换为字符 ...

  8. iOS 准确计算某个时间点距现在的时间差的代码 如"几分钟,几小时,几秒之前" ,

    利用时间戳来进行计算  ,需要给它一个时间: NSString *countTime = [self intervalSinceNow:@"2015-10-29 17:00:00" ...

  9. 记OC迁移至swift中笔记20tips

    写久了OC后来写swift,总感觉写着是swift的皮毛,但是实际上是OC的核心,这里整理了OC迁移至swift中的一些小细节. 1 在当前类中,实例方法调用属性以及方法都可以将self省略掉,而且是 ...

  10. iOS App打包流程

    1.什么是打包 将应用程序统一放在一个后缀是ipa的文件中,然后发给其他人,可以安装在手机上供用户或测试人员安装 2.可安装ipa的前提 ①说清楚是哪一个应用程序(App Id) ②可以安装在哪一台设 ...