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 >
界面效果如下:
相关推荐
IT之家 2020-03-11
graseed 2020-10-28
zbkyumlei 2020-10-12
SXIAOYI 2020-09-16
jinhao 2020-09-07
impress 2020-08-26
liuqipao 2020-07-07
淡风wisdon大大 2020-06-06
yoohsummer 2020-06-01
chenjia00 2020-05-29
baike 2020-05-19
扭来不叫牛奶 2020-05-08
hxmilyy 2020-05-11
黎豆子 2020-05-07
xiongweiwei00 2020-04-29
Cypress 2020-04-25
冰蝶 2020-04-20