表格布局类似Html里面的Table。每一个TableLayout里面有表格行TableRow,TableRow里面可以具体定义每一个元素,设定他的对齐方式 android:gravity="",如:
<TableLayout > 是顶级元素,说明采用的是表格布局
<TableRow> 定义一个行
<TextView > 定义一个单元格的内容
布局如下:
<?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:gravity="center" android:padding="2dip" android:text="@string/name" /> <TextView android:gravity="center" android:padding="2dip" android:text="@string/gender" /> <TextView android:gravity="center" android:padding="2dip" android:text="@string/age" /> <TextView android:gravity="center" android:padding="2dip" android:text="@string/phonenum" /> </TableRow> <TableRow> <TextView android:gravity="center" android:padding="2dip" android:text="@string/name1" /> <TextView android:gravity="center" android:padding="2dip" android:text="@string/gender1" /> <TextView android:gravity="center" android:padding="2dip" android:text="@string/age1" /> <TextView android:gravity="center" android:padding="2dip" android:text="@string/phonenum1" /> </TableRow> <TableRow> <TextView android:gravity="center" android:padding="2dip" android:text="@string/name2" /> <TextView android:gravity="center" android:padding="2dip" android:text="@string/gender2" /> <TextView android:gravity="center" android:padding="2dip" android:text="@string/age2" /> <TextView android:gravity="center" android:padding="2dip" android:text="@string/phonenum2" /> </TableRow> </TableLayout>android:stretchColumns="0,1,2,3"
<!-- tablelayout --> <string name="name">name</string> <string name="gender">gender</string> <string name="age">age</string> <string name="phonenum">phone_number</string> <string name="gender1">male</string> <string name="gender2">female</string> <string name="name1">jack</string> <string name="age1">25</string> <string name="phonenum1">12345</string> <string name="name2">lucy</string> <string name="age2">24</string> <string name="phonenum2">32156</string>
参考:http://simpleframework.net/blog/v/105754.html
整个android的布局和视图可以参考这篇博文点击打开链接。写的非常全!