表格布局TableLayout是Android中比較经常使用的一个布局控件,既然是表格,肯定有行和列,TableLayout中的行有TableRow组成。列依据每行控件的数量来确定

假如第一行有3个控件,第2行有4个控件,那么这个表格的列数就去最大列数,即4列。

1.属性介绍

表格有下面几个重要属性

android:shrinkColumns="2" 自己主动收缩的列。多个列用逗号隔开,自己主动收缩的意思是假设该列的内容超出了表格列的宽度,自己主动向下显示

android:stretchColumns="1" 自己主动伸缩列,多个列用逗号隔开。假设表格中全部列。都没有占满表格宽度,该列自己主动伸缩。

android:collapseColumns   隐藏指定的列,多个列用逗号隔开

android:layout_column="1" 用来设置该表格中控件所在的列数。

android:layout_span  用来设置表格中控件所占的列数

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="2"
android:stretchColumns="1"
> <TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="标签1"
android:background="#FF82AB"
/> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="标签2"
android:background="#EE6A50"
/> <TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是自己主动伸缩列。内容过多。自己主动向下伸缩"
android:background="#B3EE3A"
/> </TableRow> <TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" > <TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="标签4"
android:background="#FF82AB"
/> <TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="自己主动伸张"
android:background="#EE6A50"
/> <TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="标签6"
android:background="#B3EE3A"
/> </TableRow> </TableLayout>

2.商品列表演示样例

以下我们用TableLayout来完毕一个商品列表的布局

<?xml version="1.0" encoding="utf-8"?

>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" > <TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" >
<ImageView android:layout_width="100dp" android:layout_height="100dp" android:src="@raw/pad" />
</TableRow>
</TableLayout> <TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
> <TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
> <TableLayout android:layout_width="match_parent" android:layout_height="fill_parent" > <TableRow android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="商品名称:IPAD AIR"
android:layout_margin="10dp"
/>
</TableRow>
<TableRow android:layout_height="match_parent" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="商品价格:$99"
android:layout_margin="10dp"
/>
</TableRow> <TableRow android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="商品颜色:白色"
android:layout_margin="10dp"
/>
</TableRow> </TableLayout> </TableRow> </TableLayout> </TableRow> <TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="#EEE8CD"
> <TextView
android:layout_width="fill_parent"
android:layout_height="3dp"
android:background="#EEE8CD"
/> </TableRow> <TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" >
<ImageView android:layout_width="100dp" android:layout_height="100dp" android:src="@raw/pad" />
</TableRow>
</TableLayout> <TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
> <TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
> <TableLayout android:layout_width="match_parent" android:layout_height="fill_parent" > <TableRow android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="商品名称:IPAD AIR"
android:layout_margin="10dp"
/>
</TableRow>
<TableRow android:layout_height="match_parent" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="商品价格:$99"
android:layout_margin="10dp"
/>
</TableRow> <TableRow android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="商品颜色:白色"
android:layout_margin="10dp"
/>
</TableRow> </TableLayout> </TableRow> </TableLayout> </TableRow> <TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="#EEE8CD"
> <TextView
android:layout_width="fill_parent"
android:layout_height="3dp"
android:background="#EEE8CD"
/> </TableRow> <TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" >
<ImageView android:layout_width="100dp" android:layout_height="100dp" android:src="@raw/pad" />
</TableRow>
</TableLayout> <TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
> <TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
> <TableLayout android:layout_width="match_parent" android:layout_height="fill_parent" > <TableRow android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="商品名称:IPAD AIR"
android:layout_margin="10dp"
/>
</TableRow>
<TableRow android:layout_height="match_parent" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="商品价格:$99"
android:layout_margin="10dp"
/>
</TableRow> <TableRow android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="商品颜色:白色"
android:layout_margin="10dp"
/>
</TableRow> </TableLayout> </TableRow> </TableLayout> </TableRow> <TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="#EEE8CD"
> <TextView
android:layout_width="fill_parent"
android:layout_height="3dp"
android:background="#EEE8CD"
/> </TableRow> </TableLayout>



.Net程序猿玩转Android开发---(8)表格布局TableLayout的更多相关文章

  1. .Net程序猿玩转Android开发---(6)线性布局LinearLayout

                                LinearLayout控件是Android中重要的布局控件,是一个线性控件,所谓线性控件的意思是指该控件里面的内容仅仅能水平或垂直排列.也就 ...

  2. .Net程序猿玩转Android开发---(7)相对布局RelativeLayout

                 相对布局RelativeLayout是Android布局中一个比較经常使用的控件,使用该控件能够布局出适合各种屏幕分辨率的布局,RelativeLayout採用相对位置进行 ...

  3. .Net程序猿玩转Android开发---(11)页面跳转

    在不论什么程序开发中,都会遇到页面之间跳转的情况,Android开发也不例外.这一节,我们来认识下Android项目中如何进行页面跳转.页面跳转分为有參数和无參数页面跳转,已经接受还有一个页面的返回值 ...

  4. .Net程序猿玩转Android开发---(3)登陆页面布局

    这一节我们来看看登陆页面如何布局.对于刚接触到Android开发的童鞋来说.Android的布局感觉比較棘手.须要结合各种属性进行设置,接下来我们由点入面来 了解安卓中页面如何布局,登陆页面非常eas ...

  5. Android 自学之表格布局 TableLayout

    表格布局(TableLayout),表格布局采用行.列的形式来管理UI组件,TableLayout并不需要明确的声明多少行,多少列,而是通过TableRow.其他组件来控制表格的行数和列数. 每次想T ...

  6. Android中的表格布局TableLayout

    表格布局最基本的三个属性: XML代码实例: <?xml version="1.0" encoding="utf-8"?> <LinearLa ...

  7. .Net程序员玩转Android开发--ListView单击事件

    public class ListViewClickActivity extends Activity {         private ListView lv;        SimpleAdap ...

  8. Android开发-之五大布局

    在html中大家都知道布局是什么意思了,简单来说就是将页面划分模块,比如html中的div.table等.那么Android中也是这样的.Android五大布局让界面更加美化,开发起来也更加方便.当然 ...

  9. android开发学习---layout布局、显示单位和如何进行单元测试

    一.五大布局(layout) android中的用五大布局:LinearLayout (线性布局).AbsoluteLayout(绝对布局).RelativeLayout(相对布局).TableLay ...

随机推荐

  1. OCR识别流程

    1.图像输入.预处理:图像输入:对于不同的图像格式,有着不同的存储格式,不同的压缩方式.预处理:主要包括二值化,噪声去除,倾斜较正等2.二值化:对摄像头拍摄的图片,大多数是彩色图像,彩色图像所含信息量 ...

  2. PHP奇趣笔试试题一则

    $a = 3; $b = 5; if($a = 5 || $b = 7){ $a++; $b++; } echo $a, ' ', $b; 输出结果为: A.6 8 B.6 6 C.2 6 D.1 6 ...

  3. Android开发之BroadcastReceiver的使用

    1.静态注册. 在manifest中注册. <receiver android:name="com.exce.learnbroadcastreceiver.MyReceiver&quo ...

  4. ☀【DOM对象 / jQuery对象】

    jQuery对象和DOM对象 √http://www.ituring.com.cn/article/38868 <!DOCTYPE html> <html lang="zh ...

  5. DD_belatedPNG,IE6下PNG透明解决方案

    我们知道IE6是不支持透明的PNG的,这无疑限制了网页设计的发挥空间. 然而整个互联网上解决这个IE6的透明PNG的方案也是多不胜数,从使用IE特有的滤镜或是e­xpression,再到javascr ...

  6. ASP.NET MVC 3.0 Controller基础

    ASP.NET MVC 3.0 Controller基础   1.Controller类与方法 Controller(控制器)是ASP.NET MVC的核心,负责处理浏览器请求,并作出响应.Cotro ...

  7. vs2010常见错误

    安装vs2013以后,链接数据库总是报内存损坏,无法写入的错误 安装vs2013以后,链接数据库总是报内存损坏,无法写入的错误 用VS2012调试时发现在调用数据集时提示“尝试读取或写入受保护的内存. ...

  8. 五指CMS v1.2 GBK 发布下载

    五指CMS v1.2 GBK 版本下载地址: http://www.wuzhicms.com/uploadfile/wuzhicms/wuzhicms-v1.2.zip       从内测到公测,五指 ...

  9. ACM 2015年上海区域赛A题 HDU 5572An Easy Physics Problem

    题意: 光滑平面,一个刚性小球,一个固定的刚性圆柱体 ,给定圆柱体圆心坐标,半径 ,小球起点坐标,起始运动方向(向量) ,终点坐标 ,问能否到达终点,小球运动中如果碰到圆柱体会反射. 学到了向量模板, ...

  10. shell脚本应用(2)--变量,数值和字符串

    变量 定义,赋值: var=value 引用 $var,${var} 特殊变量 $?上条命令状态 $*/$@所有参数列表 $#参数个数 $0执行的命令名称 $1/${10}第1/10个参数 数值运算 ...