.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 ...
随机推荐
- 李洪强实现横向滚动的View<一>
今天做一个小的view的效果(纯代码),虽然这个view做起来 并不是很难,但是他是为后面我要实现的功能做一个铺垫. 01 创建CFTyreView,继承自UIView 02 来到.m文件. 2.1 ...
- IDM和ODM
DM (Integrated Data Multiplexer):综合数据复用器[1] 综合数据复用器是一种数据复用设备,它可以将多路RS232.RS485及数字语音等多种数据复用到E1传输通道或光 ...
- INCOIN Importing Multilingual Items (Doc ID 278126.1)
APPLIES TO: Oracle Inventory Management - Version: 11.5.9 to 11.5.10.CU2 - Release: 11.5 to 11.5 GOA ...
- BGP详解
相信各位站长在托管服务器或者选择虚拟主机的时候,提供商都会说他们的机房是双线机房,保证你的站点访问速度,那么这里所谓的双线机房到底是何意思,它又为何能提升站点的访问速度呢? 一遍小型机房的所谓双线路其 ...
- usaco4.12Fence Rails(迭代加深)
为了这题还去学了下迭代加深 回来还是不会写 只好参考各大神的代码及题解了 二分枚举最大可以切的块数 然后就是各种分析及优化 USACO题解里写了7个优化.. 问题分析 抽象一下就可以发现,算法的本质是 ...
- Linux Kernel ‘write_tag_3_packet()’函数本地基于堆的缓冲区溢出漏洞
漏洞名称: Linux Kernel ‘write_tag_3_packet()’函数本地基于堆的缓冲区溢出漏洞 CNNVD编号: CNNVD-201311-067 发布时间: 2013-11-07 ...
- [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.2.4
(1). The singular value decomposition leads tot eh polar decomposition: Every operator $A$ can be wr ...
- STL总结之queue, priority_queue, stack
之所以把这三个容器放在一起,是因为他们都是容器适配器. STL中queue就是我们常用的FIFO队列,实现是一个容器适配器,这种数据结构在网络中经常使用. queue的模板声明: templa ...
- POJ 3342 (树形DP)
题意 :给出一些上下级关系,要求i和i的直接上级不能同时出现,现在选出一些人构成一个集合,问你这个集合里面的最大人数是都少,同时给出这个最大的人数的集合是否唯一. 思路:树形DP,dp[i][0],表 ...
- 1到n数组,和为指定数所有序列问题
(1)方法一,背包问题解法 #include <iostream> using namespace std; #include <vector> #include <li ...