Android开发教程:表格布局的简单使用
风格跟HTML中的表格布局接近,只是所采用的标签有所不同;在这里<TableLayout>是顶级元素,说明采用的是表格布局;<TableRow>定义行,是行标签;<TextView>定义一个单元格内容,是列标签,相当于html中的td标签
在这里可以有Android:stretchColumns属性值指定列数,也可以不指定,直接写。由gravity指定文字对齐方式,padding指定视图与视图内容间的空隙,单位为像素由dip表示,作用于px相同,也可写px
string.xml文件内容:
- <stringnamestringname="name">联系人姓名</string>
- <string name="gender">性别</string>
- <string name="gender1">男</string>
- <string name="gender2">女</string>
- <string name="number">联系人电话</string>
- <stringnamestringname="name1">Sunny</string>
- <stringnamestringname="number1">1111111111</string>
- <stringnamestringname="name2">Heyley</string>
- <stringnamestringname="number2">00000000000</string>
- <stringnamestringname="name3">Army</string>
- <stringnamestringname="number3">2222222222</string>
- <stringnamestringname="name4">Jone</string>
- <stringnamestringname="number4">3333333333</string>
- <stringnamestringname="name5">David</string>
- <stringnamestringname="number5">4444444444</string>
- <stringnamestringname="name6">John</string>
- <stringnamestringname="number6">55555555555</string>
main.xml文件内容:
- <?xmlversionxmlversion="1.0" encoding="utf-8"?>
- <TableLayoutxmlns:androidTableLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:stretchColumns="0,1,2">
- <TableRow>
- <TextView
- android:text="@string/name"
- android:gravity="center"
- android:padding="3px"/>
- <TextView
- android:text="@string/gender"
- android:gravity="center"
- android:padding="3px"/>
- <TextView
- android:text="@string/number"
- android:gravity="center"
- android:padding="3px"/>
- </TableRow>
- <TableRow>
- <TextView
- android:text="@string/name1"
- android:gravity="center"
- android:padding="3px"/>
- <TextView
- android:text="@string/gender2"
- android:gravity="center"
- android:padding="3px"/>
- <TextView
- android:text="@string/number1"
- android:gravity="center"
- android:padding="3px"/>
- </TableRow>
- <TableRow>
- <TextView
- android:text="@string/name2"
- android:gravity="center"
- android:padding="3px"/>
- <TextView
- android:text="@string/gender2"
- android:gravity="center"
- android:padding="3px"/>
- <TextView
- android:text="@string/number2"
- android:gravity="center"
- android:padding="3px"/>
- </TableRow>
- <TableRow>
- <TextView
- android:text="@string/name6"
- android:gravity="center"
- android:padding="3px"/>
- <TextView
- android:text="@string/gender1"
- android:gravity="center"
- android:padding="3px"/>
- <TextView
- android:text="@string/number6"
- android:gravity="center"
- android:padding="3px"/>
- </TableRow>
- <TableRow>
- <TextView
- android:text="@string/name5"
- android:gravity="center"
- android:padding="3px"/>
- <TextView
- android:text="@string/gender1"
- android:gravity="center"
- android:padding="3px"/>
- <TextView
- android:text="@string/number5"
- android:gravity="center"
- android:padding="3px"/>
- </TableRow>
- <TableRow>
- <TextView
- android:text="@string/name4"
- android:gravity="center"
- android:padding="3px"/>
- <TextView
- android:text="@string/gender1"
- android:gravity="center"
- android:padding="3px"/>
- <TextView
- android:text="@string/number4"
- android:gravity="center"
- android:padding="3px"/>
- </TableRow>
- <TableRow>
- <TextView
- android:text="@string/name3"
- android:gravity="center"
- android:padding="3px"/>
- <TextView
- android:text="@string/gender2"
- android:gravity="center"
- android:padding="3px"/>
- <TextView
- android:text="@string/number3"
- android:gravity="center"
- android:padding="3px"/>
- </TableRow>
- </TableLayout>
效果图:
设计思路:该表格布局主要分为了七行三列,使用文本是string.xml文件中的文本
相关推荐
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