Android_007_Activity控件布局_TableLayout
TableLayout, 顾名思义, 就 “表格样式的布局”
在xml的布局文件中, 是以 <TableLayout></TableLayout> 为根标签.
然后以 <TableRow></TableRow>来定义每一行, 在这个标签里的所有控件都会在显示在同一行里.
简单的例子, 以”表格样式”分别显示三个”TextView”/”EditText”/”Button”
xml布局文件中的代码如下:
<?
xml version="1.0" encoding="utf-8"
?>
< TableLayout xmlns:android ="http://schemas.android.com/apk/res/android"
android:layout_height ="wrap_content"
android:id ="@+id/tableLayout1"
android:layout_width ="match_parent" >
< TableRow
android:id ="@+id/tableRow1"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content" >
< TextView
android:id ="@+id/TextView11"
android:text ="@string/TextView11"
android:textColor ="#ff0000"
/>
< TextView
android:id ="@+id/TextView12"
android:text ="@string/TextView12"
android:textColor ="#00ff00"
/>
< TextView
android:id ="@+id/TextView13"
android:text ="@string/TextView13"
android:textColor ="#ffffff"
/>
</ TableRow >
< TableRow
android:id ="@+id/tableRow2"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content" >
< EditText
android:id ="@+id/EditText21"
android:background ="#ff0000"
/>
< EditText
android:id ="@+id/EditText22"
android:background ="#00ff00"
/>
< EditText
android:id ="@+id/EditText23"
android:background ="#ffffff"
/>
</ TableRow >
< TableRow
android:id ="@+id/tableRow3"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content" >
< Button
android:id ="@+id/Button31"
android:text ="@string/Button31"
android:textColor ="#ff0000"
/>
< Button
android:id ="@+id/Button32"
android:text ="@string/Button32"
android:textColor ="#00ff00"
/>
< Button
android:id ="@+id/Button33"
android:text ="@string/Button33"
android:textColor ="#ffffff"
/>
</ TableRow >
</ TableLayout >
< TableLayout xmlns:android ="http://schemas.android.com/apk/res/android"
android:layout_height ="wrap_content"
android:id ="@+id/tableLayout1"
android:layout_width ="match_parent" >
< TableRow
android:id ="@+id/tableRow1"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content" >
< TextView
android:id ="@+id/TextView11"
android:text ="@string/TextView11"
android:textColor ="#ff0000"
/>
< TextView
android:id ="@+id/TextView12"
android:text ="@string/TextView12"
android:textColor ="#00ff00"
/>
< TextView
android:id ="@+id/TextView13"
android:text ="@string/TextView13"
android:textColor ="#ffffff"
/>
</ TableRow >
< TableRow
android:id ="@+id/tableRow2"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content" >
< EditText
android:id ="@+id/EditText21"
android:background ="#ff0000"
/>
< EditText
android:id ="@+id/EditText22"
android:background ="#00ff00"
/>
< EditText
android:id ="@+id/EditText23"
android:background ="#ffffff"
/>
</ TableRow >
< TableRow
android:id ="@+id/tableRow3"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content" >
< Button
android:id ="@+id/Button31"
android:text ="@string/Button31"
android:textColor ="#ff0000"
/>
< Button
android:id ="@+id/Button32"
android:text ="@string/Button32"
android:textColor ="#00ff00"
/>
< Button
android:id ="@+id/Button33"
android:text ="@string/Button33"
android:textColor ="#ffffff"
/>
</ TableRow >
</ TableLayout >
运行的结果如下图所示: