Android应用开发之TableLayout (表格布局)+信息列表案例

表格布局的风格跟 HTML 中的表格比较接近,只是所采用的标签不同。

□<TableLayout > 是顶级元素,采用的是表格布局

□ <TableRow> 定义一个行

□ <TextView > 定义一个单元格的内容

示例main.xml布局文件内容如下:

<? xml version = "1.0"encoding = "utf-8" ?>
< TableLayout
xmlns:android = "http://schemas.android.com/apk/res/android
android:layout_width ="fill_parent"
android:layout_height ="fill_parent"
android:stretchColumns ="0,1,2,3"
> 
< TableRow >
< TextView
android:text = "@string/name"
android:gravity = "center"
android:padding = "3dip" />
< TextView
android:text = "@string/gender"
android:gravity = "center"
android:padding = "3dip" />
< TextView
android:text = "@string/age"
android:gravity = "center"
android:padding = "3dip" />
< TextView
android:text = "@string/phonenum"
android:gravity = "center"
android:padding = "3dip" />
</ TableRow >
< TableRow >
< TextView
android:text = "@string/name1"
android:gravity = "center"
android:padding = "3dip" />
< TextView
android:text = "@string/gender1"
android:gravity = "center"
android:padding = "3dip" />
< TextView
android:text = "@string/age1"
android:gravity = "center"
android:padding = "3dip" />
< TextView
android:text ="@string/phonenum1"
android:gravity = "center"
android:padding = "3dip" />
</ TableRow >
< TableRow >
< TextView
android:text = "@string/name2"
android:gravity = "center"
android:padding = "3dip" />
< TextView
android:text = "@string/gender1"
android:gravity = "center"
android:padding = "3dip" />
< TextView
android:text = "@string/age2"
android:gravity = "center"
android:padding = "3dip" />
< TextView
android:text ="@string/phonenum2"
android:gravity = "center"
android:padding = "3dip" />
</ TableRow >
</ TableLayout >

□ android:stretchColumns="0,1,2,3"

该属性指定每行都由第“ 0 、 1 、 2 、 3 ”列占满空白空间。

□ gravity 指定文字对齐方式,案例都设为居中对齐。

□ padding 指定视图与视图内容间的空隙,单位为像素。

对应的 strings.xml 文件内容如下:

<? xml version = "1.0"encoding = "utf-8" ?>
< resources >
< string name = "name" > 姓名 </string >
< string name = "gender" > 性别 </string >
< string name = "age" > 年龄 </string >
< string name = "phonenum"> 电话 </ string >
< string name = "gender1" >男 </ string >
< string name = "gender2" >女 </ string >
< string name = "name1" > 张三 </string >
< string name = "age1" > 25</ string >
< string name = "phonenum1"> 1234567 </ string >
< string name = "name2" > 李四 </string >
< string name = "age2" > 24</ string >
< string name = "phonenum2"> 7654321 </ string >
</ resources >

界面效果如下:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值