表格布局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. 如何在Blog中使用feedburner管理RSS订阅

    http://www.cnblogs.com/procoder/archive/2010/02/12/feedburner.html

  2. JAVA大数类练手

    今天突然看到了OJ上的大数类题目,由于学习了一点大数类的知识.果断水了6道题......都是非常基础的.就当的练手的吧. 学到的只是一些大数类的基本操作.以后多做点这样的题,争取熟练运用水大数题... ...

  3. 在redhat6.4下安装 Oracle® Database 11g Release 2

    OS版本: 安装过程的相关信息: pdksh 安装好后根据需要设置oracle开机自启动http://www.cnblogs.com/softidea/p/3761671.html 设置环境变量NLS ...

  4. VS2010里属性窗口中的生成操作

    ,无,编译 ,内容 ,嵌入的资源...分别是什么意思? 如果是类.cs文件,就得编译之后你才能使用的.如果是txt,excle这种文件,就属性内容或者资源文件了. @普通用户: 内容(Content) ...

  5. WCF - Versus Web Service

    There are some major differences that exist between WCF and a Web service which are listed below. 这里 ...

  6. 逻辑运算符&& 用法解释

    A&&B 首先判断A,A成功然后判断B:A不成功则结束判断,返回false;

  7. Struts 2.3.1.1 命令执行漏洞

    漏洞版本: Struts 2.3.1.1 漏洞描述: CVE ID:CVE-2011-3923 Struts2的核心使用的是WebWork框架,而WebWork通过XWork来处理用户的请求参数.Xw ...

  8. apache开源项目--kylin

    Kylin 是一个开源的分布式的 OLAP 分析引擎,来自 eBay 公司开发,基于 Hadoop 提供 SQL 接口和 OLAP 接口,支持 TB 到 PB 级别的数据量. Kylin 是: 超级快 ...

  9. MailSystem.NET Gmail IMAP讀取信件

    程式的主流程為: 開啟SSL連線,逐一讀取收信匣中的信件,將信件內文HTML及附檔逐一存檔後,再將信件移至垃圾桶. 程式碼如下,補充說明我寫在註解裡,請參考: static void Main(str ...

  10. Loadrunner执行Java脚本

    1. Eclipse中调试Java脚本,脚本调试通过后,打成jar包: 2. 新建lr脚本,选择Java vuser协议: 3. Run-time Settings中Classpath设置jar包,没 ...