.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 ...
随机推荐
- SPRING IN ACTION 第4版笔记-第七章Advanced Spring MVC-003- 上传文件multipart,配置StandardServletMultipartResolver、CommonsMultipartResolver
一.什么是multipart The Spittr application calls for file uploads in two places. When a new user register ...
- webstore+nodejs
新建一个普通的project. 编写如下代码: var http=require('http'); http.createServer(function(req,res){ res.writeHead ...
- 【HDOJ】1502 Regular Words
大数+DP,感觉这个DP有点儿抽象,而且这个是大数,wa了很多次. #include <stdio.h> #define MAXNUM 61 #define MAXLEN 100 type ...
- BOM List demo
select level level_id, t.* from (select msi1.segment1 farther_item, msi1.inv ...
- BZOJ_1016_[JSOI2008]_最小生成树计数_(dfs+乘法原理)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1016 给出一张图,其中具有相同权值的边的数目不超过10,求最小生成树的个数. 分析 生成树的计 ...
- ruby2.2.2 源代码阅读笔记
这是win32下的结构 从ruby_setup开始阅读 Ruby对象内存结构 RVALUE是一个union,内含ruby所有结构体(RBasic RObject RClass RFloat RStri ...
- Azure Site Recovery:我们对于保障您的数据安全的承诺
Anoob Backer 云 + Enterprise 项目经理 Azure Site Recovery是一个基于 Azure的全天候.易用的服务,可以安全地安排恢复操作,一旦发生灾难,即可为您 ...
- c语言诊断_断言库函数#include<assert.h>
诊断<assert.h> assert #include <assert.h> void assert(int exp); assert宏用于为程序增加诊断功能.当asser ...
- 去除浏览器下jquey easyui datagrid、combotree 缓存问题
在页面脚本中加入以下内容即可: $.ajaxSetup ({ cache: false //关闭AJAX相应的缓存 });
- JSP---JSP中4个容器-pageContext使用
这里重点只讲pageContext容器的用法哦. 因为另外的3个容器(request,session,application)在前面的servlet中已经演示过很多遍了 容器 作用域 pageCont ...