The layout style of a table is similar to that of a table in HTML, but the labels used are different.
□< TableLayout> is a top-level element and uses a table layout.
□< TableRow> define a row
□< TextView> define the content of a cell
The content of the main. xml layout file is as follows:
<? 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"
This attribute specifies that each row is filled with blank space by columns 0, 1, 2, and 3.
□Gravity specifies the text alignment mode, and the case is set to center alignment.
□Padding specifies the gap between the view and the view content, in pixels.
The content of the corresponding strings. xml file is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<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"> Michael </string>
<String name = "age1"> 25 </string>
<String name = "phonenum1"> 1234567 </string>
<String name = "name2"> Li Si </string>
<String name = "age2"> 24 </string>
<String name = "phonenum2"> 7654321 </string>
</Resources>
The interface effect is as follows:
Excerpted from the column