android布局之表单布局(TableLayout)
表单布局,要和TableLayout中的属性TableRow配合使用,我们要利用表单布局实现下图这样的一个布局,首先在这个布局中有一个表单的标题,这个表单有四列,下面分别对应相应的信息:

- <?xml version="1.0" encoding="utf-8"?>
- <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:stretchColumns="*"
- android:shrinkColumns="*">
- <!-- <pre name="code" class="html"><span style="white-space:pre"> </span>android:stretchColumns="*"将所有的列设置为伸展的,从而填充可利用的屏幕空间</pre><pre name="code" class="html"><span style="white-space:pre"></span><pre name="code" class="html"><span style="white-space:pre"> </span>android:shrinkColumns="*" 拉伸所有列,填满布局</pre><p></p>
- <pre></pre>
- -->
- <pre></pre>
- <pre name="code" class="html"> <TableRow
- android:id="@+id/tableRow4"
- android:layout_height="wrap_content"
- android:layout_width="match_parent">
- <TextView
- android:id="@+id/textView9"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textSize="18dp"
- android:text="Table 标题"
- android:gravity="center"
- android:layout_span="4"/>
- </TableRow>
- </pre><pre name="code" class="html"><span style="white-space:pre"> </span><!-- <pre name="code" class="html"> <span style="white-space:pre"> </span>android:gravity设置居中显示</pre><pre name="code" class="html"><pre name="code" class="html"><span style="white-space:pre"> </span>android:layout_span 跨四列</pre>
- <pre></pre>
- <span style="white-space:pre"></span>-->
- <pre></pre>
- <pre name="code" class="html"> <TableRow
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/name"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/sex"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/age"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/phonenumber"
- />
- </TableRow>
- <TableRow >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/nameZs"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/sexZs"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/ageZs"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/phonenumberZs"
- />
- </TableRow>
- <TableRow >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/nameLs"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/sexLs"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/ageLs"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/phonenumberLs"
- />
- </TableRow>
- </TableLayout></pre><br>
- 如有疑问清指出
- <p></p>
- </pre></pre></pre>

浙公网安备 33010602011771号