表单布局,要和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="*">
<!-- android:stretchColumns="*"将所有的列设置为伸展的,从而填充可利用的屏幕空间 android:shrinkColumns="*" 拉伸所有列,填满布局
-->
<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>
<!-- android:gravity设置居中显示 android:layout_span 跨四列
-->
<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>如有疑问清指出
本文介绍如何利用Android的TableLayout和TableRow组件创建表单布局。通过实例展示如何构建一个包含四列的表单,用于展示各种信息。
1503

被折叠的 条评论
为什么被折叠?



