.Net程序猿玩转Android开发---(8)表格布局TableLayout
表格布局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的更多相关文章
- .Net程序猿玩转Android开发---(6)线性布局LinearLayout
LinearLayout控件是Android中重要的布局控件,是一个线性控件,所谓线性控件的意思是指该控件里面的内容仅仅能水平或垂直排列.也就 ...
- .Net程序猿玩转Android开发---(7)相对布局RelativeLayout
相对布局RelativeLayout是Android布局中一个比較经常使用的控件,使用该控件能够布局出适合各种屏幕分辨率的布局,RelativeLayout採用相对位置进行 ...
- .Net程序猿玩转Android开发---(11)页面跳转
在不论什么程序开发中,都会遇到页面之间跳转的情况,Android开发也不例外.这一节,我们来认识下Android项目中如何进行页面跳转.页面跳转分为有參数和无參数页面跳转,已经接受还有一个页面的返回值 ...
- .Net程序猿玩转Android开发---(3)登陆页面布局
这一节我们来看看登陆页面如何布局.对于刚接触到Android开发的童鞋来说.Android的布局感觉比較棘手.须要结合各种属性进行设置,接下来我们由点入面来 了解安卓中页面如何布局,登陆页面非常eas ...
- Android 自学之表格布局 TableLayout
表格布局(TableLayout),表格布局采用行.列的形式来管理UI组件,TableLayout并不需要明确的声明多少行,多少列,而是通过TableRow.其他组件来控制表格的行数和列数. 每次想T ...
- Android中的表格布局TableLayout
表格布局最基本的三个属性: XML代码实例: <?xml version="1.0" encoding="utf-8"?> <LinearLa ...
- .Net程序员玩转Android开发--ListView单击事件
public class ListViewClickActivity extends Activity { private ListView lv; SimpleAdap ...
- Android开发-之五大布局
在html中大家都知道布局是什么意思了,简单来说就是将页面划分模块,比如html中的div.table等.那么Android中也是这样的.Android五大布局让界面更加美化,开发起来也更加方便.当然 ...
- android开发学习---layout布局、显示单位和如何进行单元测试
一.五大布局(layout) android中的用五大布局:LinearLayout (线性布局).AbsoluteLayout(绝对布局).RelativeLayout(相对布局).TableLay ...
随机推荐
- easyui源码翻译1.32--PropertyGrid(属性表格)
前言 继承自$.fn.datagrid.defaults.使用$.fn.propertygrid.defaults重写默认值对象.下载该插件翻译源码 属性表格提供The propertygrid pr ...
- Redisson使用起来很方便,但是需要redis环境支持eval命令
Redisson使用起来很方便,但是需要redis环境支持eval命令,否则一切都是悲剧,比如me.结果还是要用RedisCommands去写一套.例子就如下,获得一个RLock锁对象,然后tryLo ...
- linux下 修改配置文件的命令
vi或vim 进入后,按i,屏幕下方会出现INSERT字样,此时可以修改内容 按ESC,退回命令模式 :x是保存退出 :q!是不保存退出
- Leap Years
Description: In this kata you should simply determine, whether a given year is a leap year or not. I ...
- BZOJ_1622_[Usaco2008_Open]_Word_Power_名字的能量_(字符匹配_暴力)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1622 给出多个文本串和模式串,求每个文本串中有多少模式串. 分析 直接暴力... #inclu ...
- Mysql监控工具小集合
介绍一些常见的Mysql监控工具. Cacti Cacti是 一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具.它通过snmpget来获取数据,使用 RRDtool绘 ...
- HDU 2682
思路:由于题目对能相连的点有限制,必须将这些点处理,能相连的点合并到一个集合中,最后查看是否所有点都在一个集合里,若都在说明是一个连通图,存在最小生成树,否则图不连通,不存在最小花费. #includ ...
- [liu yanling]测试用例设计综合策略
Myers提出了使用各种测试方法的综合策略: 1) 在任何情况下都必须使用边界值分析方法,经验表明用这种方法设计出测试用例发现程序错误的能力最强. 2) 必要时用等价类划分方法补充一些测试 ...
- Selenium IDE初探
系列教程: http://www.cnblogs.com/hyddd/archive/2009/05/30/1492536.html 使用过程中,出现了一些问题.
- 【CSS3】Advanced11:Media Queries
1.Browser-size specific CSS @media screen and (max/min-width:1000px){} 2.Orientation-specific CSS? @ ...