android布局之表单布局(TableLayout)

本文介绍如何利用Android的TableLayout和TableRow组件创建表单布局。通过实例展示如何构建一个包含四列的表单,用于展示各种信息。

表单布局,要和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>

如有疑问清指出

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值