表格布局模型以行列的形式管理子控件,每一行为一个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 表格布局,FrameLaout 帧布局 ,AbsoluteLayout绝对布局的分析

    这三个布局就放在一起来写了他们用的比较少,不过为了写这遍 博客我换特意去复习了下, 第一个表格布局TableLayout 表格布局顾名思义 就是与表格类似,以行,列形式来管理其中的组件的, 它是< ...

  2. android表格布局最后一个组件,Android布局之TableLayout表格布局

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

  3. 安卓APP_ 布局(4) —— TableLayout表格布局

    摘自:安卓APP_ 布局(4) -- TableLayout表格布局 作者:丶PURSUING 发布时间: 2021-04-11 22:55:50 网址:https://blog.csdn.net/w ...

  4. android html 显示表格边框,tablelayout表格布局详解

    如果你已经下载好MT4软件(很多专业外汇平台都有提供下载的),在手机桌面找到图表打开,然后选择好交易商,输入账号密码就可以了. TableLayout怎样实现表格布局 表格布局的子对象不能指定 lay ...

  5. Android 应用开发(38)TableLayout(表格布局)

    TableLayout(表格布局) 前面我们已经学习了平时实际开发中用得较多的线性布局(LinearLayout)与相对布局(RelativeLayout), 其实学完这两个基本就够用了,笔者在实际开 ...

  6. android简单实现表格布局,Android开发中TableLayout表格布局

    Android开发中TableLayout表格布局 一.引言 在移动端应用程序开发中,常常会使用到表格布局,iOS和Android开发框架中都提供了独立的表格视图控件供开发者使用,例如iOS中的UIT ...

  7. 第15章、布局Layouts之TableLayout表格布局(从零开始学Android)

    TableLayout表格布局 TableLayout是指将子元素的位置分配到行或列中.Android的一个TableLayout有许多TableRow组成,每一个TableRow都会定义一个Row. ...

  8. Android基础入门教程——2.2.3 TableLayout(表格布局)

    Android基础入门教程--2.2.3 TableLayout(表格布局) 标签(空格分隔): Android基础入门教程 本节引言: 前面我们已经学习了平时实际开发中用得较多的线性布局(Linea ...

  9. 【Android 】零基础到飞升 | TableLayout(表格布局)

    2.2.3 TableLayout(表格布局) 本节引言: 前面我们已经学习了平时实际开发中用得较多的线性布局(LinearLayout)与相对布局(RelativeLayout), 其实学完这两个基 ...

  10. 3.2.3 TableLayout(表格布局)

    3.2.3 TableLayout(表格布局) 标签: StudyNote 本文声明: 本文由Coder-pig编写,想了解其他内容,可见CoderPig's Android Study Note-- ...

最新文章

  1. python提取两个引号中的内容,怎样用 Python 提取不在双引号的内容?
  2. fpga经典设计100例_图解运放电路/OP放大电路设计/OP放大器应用技巧100例
  3. 服务器数据恢复难题--操作系统恢复的方法和思路
  4. nyist 541最强DE 战斗力
  5. springboot怎么杀进程_全新Steam在线游戏 Among us太空狼人杀攻略
  6. php判断是否为数字_PHP知识点:从'xulei' == 0是否为真谈谈运算符===和==
  7. 程序员版的《后来的我们》,结局竟是……
  8. 运行elasticsearch时报错:could not find java; set JAVA_HOME or ensure java is in PATH
  9. 钉钉日志范文100篇_工作日志应该怎么写?——以钉钉日报模板举例告诉你
  10. 海康摄像头使用网线连接电脑后无法访问摄像头ip
  11. 卡特彼勒CAT SIS 售后服务系统3D零件图系统软件 2019年最新版
  12. hdu 4311 4312 Meeting point 曼哈顿距离之和最小
  13. 热释电探测器多用在_热释电红外探测器
  14. OpenCV在图片上画线和矩形
  15. 加州洛杉矶计算机研究生,加州洛杉矶计算机硕士文书要求
  16. 江湖中常说的“网格交易法”到底是什么?
  17. 清华大学计算机系高考生源,清华在京录取圆满结束:生源好、质量优、扩幅大(转贴)...
  18. 英特尔诺基亚发布MeeGo移动版操作系统
  19. android车机启动器,【分享】车载启动器 AG 车载桌面启动器1.5.1车机桌面
  20. Verilog 6位数码管LG3661BH 的动态显示

热门文章

  1. Amazon AWS云计算服务平台概述
  2. [Spring mvc 深度解析(二)] Tomcat分析
  3. keep-alive的深入理解与使用(配合router-view缓存整个路由页面)
  4. 创立创造创建的区别_【干货|知识分享】Solidworks与Rhino有什么区别呢?
  5. 4444端口 linux,Docker Container无法访问本地主机端口4444。为什么?
  6. 谷歌翻译无法连接网络_Windows无法连接网络,这几招教你解决
  7. unity模块切换_(一)Unity3D模块介绍
  8. r语言logistic回归_R语言多分类logistic逻辑回归模型在混合分布模拟单个风险损失值评估的应用...
  9. 遴选中计算机类,计算机卓越班遴选办法-计算机学院
  10. oracle or条件后 排序,WHERE条件和排序