TableLayout跟TableRow 是一组搭配应用的布局,TableLayout置底,TableRow在TableLayout的上方,而Button、TextView等控件就在TableRow之上,别的,TableLayout之上也可以零丁放控件。TableLayout是一个应用错杂的布局,最简单的用法就仅仅是拖沓控件做出个界面,但实际上,会经常在代码里应用TableLayout,例如做出表格的结果。本文首要介绍TableLayout的根蒂根基应用办法。
重要的几个属性如下:
1.android:collapseColumns://隐藏指定的列
①设置 TableLayout 内的 TableRow 中需要隐藏的列的列索引,多个用“,”隔开
②以第0行为序,隐藏指定的列:把android:collapseColumns=0,3 意思是把第0和第3列隐藏
2.android:shrinkColumns://收缩指定的列以适合屏幕、不会挤出屏幕 ① 设置 TableLayout 内的 TableRow 中需要拉伸(该列会拉伸到所有可用空间)的列的列索引,多列个用“,”隔开(多列 每列填充空隙大小一样)
②以第0行为序,自动延伸指定的列填充可用部分: 当LayoutRow里面的控件还没有布满布局时,shrinkColumns不起作用。
③设置了shrinkColumns=1,4,布局完全没有改变,因为LayoutRow里面还剩足够的空间。当LayoutRow布满控件时,设置了shrinkColumns=2,5,则控件自动向垂直方向填充空间

3.android:stretchColumns://尽量把指定的列表填充空白部分
①设置 TableLayout 内的 TableRow 中需要收缩(为了使其他列不会被挤到屏幕 外,此列会自动收缩)的列的列索引,多个用“,”隔开
② 以第0行为序,尽量把指定的列填充空白部分:设置stretchColumns=2,5,第1,4列被尽量填充同时向右填充,直到2,5被压挤到最后边)。

补充:
①表格布局的子对象不能指定 layout_width 属性.宽度永远是 MATCH_PARENT。
②不过子对象可以定义 layout_height 属性;其默认值是WRAP_CONTENT. 如果子对象是 TableRow,其高度永远是 WRAP_CONTENT。
实例:

001 |
< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" |
002 |
xmlns:tools = "http://schemas.android.com/tools" |
003 |
android:layout_width = "match_parent" |
004 |
android:layout_height = "match_parent" |
005 |
android:orientation = "vertical" |
006 |
tools:context = ".AndroidTableLayoutActivity" > |
008 |
<!-- 定义第一个表格,指定第2列允许收缩,第3列允许拉伸 --> |
011 |
android:id = "@+id/tablelayout01" |
012 |
android:layout_width = "match_parent" |
013 |
android:layout_height = "wrap_content" |
014 |
android:shrinkColumns = "1" |
015 |
android:stretchColumns = "2" > |
017 |
<!-- 直接添加按钮,自己占用一行 --> |
020 |
android:id = "@+id/btn01" |
021 |
android:layout_width = "wrap_content" |
022 |
android:layout_height = "wrap_content" |
023 |
android:text = "独自一行" > |
029 |
android:id = "@+id/btn02" |
030 |
android:layout_width = "wrap_content" |
031 |
android:layout_height = "wrap_content" |
036 |
android:id = "@+id/btn03" |
037 |
android:layout_width = "wrap_content" |
038 |
android:layout_height = "wrap_content" |
039 |
android:text = "允许被收缩允许被收缩允许被收缩允许被收缩" > |
043 |
android:id = "@+id/btn04" |
044 |
android:layout_width = "wrap_content" |
045 |
android:layout_height = "wrap_content" |
046 |
android:text = "允许被拉伸允许被拉伸允许被拉伸" > |
050 |
<!-- 定义第2个表格,指定第2列隐藏 --> |
053 |
android:id = "@+id/tablelayout02" |
054 |
android:layout_width = "match_parent" |
055 |
android:layout_height = "wrap_content" |
056 |
android:collapseColumns = "1" > |
061 |
android:id = "@+id/btn05" |
062 |
android:layout_width = "wrap_content" |
063 |
android:layout_height = "wrap_content" |
068 |
android:id = "@+id/btn06" |
069 |
android:layout_width = "wrap_content" |
070 |
android:layout_height = "wrap_content" |
071 |
android:text = "被隐藏列" > |
075 |
android:id = "@+id/btn07" |
076 |
android:layout_width = "wrap_content" |
077 |
android:layout_height = "wrap_content" |
078 |
android:text = "允许被拉伸" > |
082 |
<!-- 定义第3个表格,指定第2列填满空白 --> |
085 |
android:id = "@+id/tablelayout03" |
086 |
android:layout_width = "match_parent" |
087 |
android:layout_height = "wrap_content" |
088 |
android:stretchColumns = "1" > |
093 |
android:id = "@+id/btn08" |
094 |
android:layout_width = "wrap_content" |
095 |
android:layout_height = "wrap_content" |
100 |
android:id = "@+id/btn09" |
101 |
android:layout_width = "wrap_content" |
102 |
android:layout_height = "wrap_content" |
103 |
android:text = "填满剩余空白" > |
107 |
<!-- 定义第3个表格,指定第2列横跨2列 --> |
110 |
android:id = "@+id/tablelayout04" |
111 |
android:layout_width = "match_parent" |
112 |
android:layout_height = "wrap_content" > |
117 |
android:id = "@+id/btn10" |
118 |
android:layout_width = "wrap_content" |
119 |
android:layout_height = "wrap_content" |
124 |
android:id = "@+id/btn11" |
125 |
android:layout_width = "wrap_content" |
126 |
android:layout_height = "wrap_content" |
127 |
android:layout_column = "2" |
128 |
android:text = "填满剩余空白" > |
- Android ActionBar详解(三):ActionBar实现切换Tabs标签
实现切换Tabs标签; Activity代码: public class ActionBarTabs extends Activity { @Override protected void onCre ...
- Html5移动端页面自适应布局详解(阿里rem布局)
在移动设备上进行网页的重构或开发,首先得搞明白的就是移动设备上的viewport,通读网上的各种对于viewport的解释之后 大概viewport可以理解为三种 1.layout viewport ...
- (转)android Fragments详解三:实现Fragment的界面
为fragment添加用户界面 fragment一般作为activity的用户界面的一部分,把它自己的layout嵌入到activity的layout中. 一个 要为fragment提供layo ...
- 【转】Android编译系统详解(三)——编译流程详解
原文网址:http://www.cloudchou.com/android/post-276.html 本文原创作者:Cloud Chou. 欢迎转载,请注明出处和本文链接 1.概述 编译Androi ...
- Android Fragment详解(三): 实现Fragment的界面
为fragment添加用户界面: Fragment一般作为activity的用户界面的一部分,把它自己的layout嵌入到activity的layout中. 一个 要为fragment提供layout ...
- Android ActionBar详解(三)--->ActionBar的Home导航功能
FirstActivity如下: package cc.testsimpleactionbar2; import android.os.Bundle; import android.app.Activ ...
- Android Loader详解三:重启与回调
重启装载器 当你使用initLoader()时,如果指定ID的装载器已经存在,则它使用这个装载器.如果不存在呢,它将创建一个新的.但是有时你却是想丢弃旧的然后开始新的数据. 要想丢弃旧数据,你应使用r ...
- Android 布局详解
Android 布局详解 1.重用布局 当一个布局文件被多处使用时,最好<include>标签来重用布局. 例如:workspace_screen.xml的布局文件,在另一个布局文件中被重 ...
- Grid 网格布局详解
Grid网格布局详解: Grid布局与Flex布局有着一定的相似性,Grid布局是将容器划分成行和列,产生单元格,可以看做是二维布局. 基本概念: 采用网格布局的区域,称为"容器" ...
随机推荐
- Guava Files 源码分析(一)
Files中的工厂 Files类中对InputStream, OutputStream以及Reader,Writer的操作封装了抽象工厂模式,抽象工厂是InputSupplier与OutputSupp ...
- Spark从HDFS上读取JSON数据
代码如下: import org.apache.spark.sql.Row; import org.apache.spark.SparkConf; import org.apache.spark.ap ...
- Objective-C:NSArray的常见操作
NSArray不可变字符串的主要操作有:创建.枚举.排序.与NSString之间的相互转换 注意: NSArray可以存对象,不可以存基本数据类型.结构体.数组.指针.nil.NULL NSArray ...
- 支持5G-WiFi的安卓设备搜索不到5G信号解决方法
安卓设备必须获得root权限,然后修改 /system/etc/wifi/nvram_net.txt 文件, 将ccode = CN 改为 ccode = ALL.保存并重启即可. 三星EK-GC11 ...
- JQuery缓冲加载图片插件lazyload.js的使用方法
lazyload.js是一个基于JQuery的插件,可以用来缓冲加载图片.如果一个网页很长并且有很多图片的话,下载图片就需要很多时间,那么就会影响整个网页的加载速度,而这款延迟加载插件,会通过你的滚动 ...
- IOS info.plist配置文件
创建ios程序时,系统会自动生成一个info.plist文件,它是一个必不可少的文件,因为在这个文件中,存放是应用程序的配置信息,比如本地化语言.版本号.软件名称等,当然,我们也可以在项目的属性中进行 ...
- android 多线程概述
android多线程,一直是一个麻烦的事情,要掌握它的本质,我们需要搞清楚一个问题,linux多线程的本质. 我们这篇文章,来讨论以下的议程: 了解linux的历程,了解android的异步任务机制, ...
- centos7 JDK1.8
安装之前先检查一下系统有没有自带open-jdk rpm -qa |grep java rpm -qa |grep jdk 卸载找出的已安装Java相关rpm文件:rpm -e --nodeps 重新 ...
- 自适应图片宽度的jQuery焦点幻灯轮播代码
自适应图片宽度的jQuery焦点幻灯轮播代码 注意要1.7.2版本的jq才支持点击后显示点击的图片,不然就是一直顺序播放 演示 XML/HTML Code <div id="sli ...
- HDU 4585 Shaolin (STL)
没想到map还有排序功能,默认按照键值从小到大排序 #include <cstdio> #include <iostream> #include <cstring> ...