表格布局管理器的常用属性(自用)

                        表格布局管理器的常用属性

TableLayout是采用表格的形式对控件的布局进行管理的,在TableLayout布局管理器之中,要使用TableRow进行表格行的控制,之后所有组件要在TableRow中添加。
大体直观印象如:
这里写图片描述

tablelayout和tablerow常用属性,个人觉得基本一样:
tablelayout是继承了linerlayout,因此它又完全支持linerlayout所支持的全部XML属性,此外:
他还拥有以下3种常用属性:

  1. Android:collapseColumns
    • 设置需要被隐藏的列的列序号(序号从0开始),多个列序号之间用逗号”,”分隔
  2. Android:shrinkColumns
    • 设置允许被收缩的列的列序号(序号从0开始),多个列序号之间用逗号”,”分隔
  3. Android:stretchColumns
    • 设置允许被拉伸的列的列序号(序号从0开始),多个列序号之间用逗号”,”分隔

引用《Android从入门到精通》明日科技编著 书内的一个例子:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@+id/tableLayout1"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/background_a"
    android:gravity="center_vertical"
    android:stretchColumns="0,3"    
    >
    <!-- 第一行 -->
    <TableRow android:id="@+id/tableRow1" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView/>
        <TextView android:text="用户名:" 
            android:id="@+id/textView1" 
            android:layout_width="wrap_content"
            android:textSize="24px" 
            android:layout_height="wrap_content"
            />
        <EditText android:id="@+id/editText1" 
            android:textSize="24px" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" android:minWidth="200px"/>
        <TextView />
    </TableRow>
    <!-- 第二行 -->    
    <TableRow android:id="@+id/tableRow2" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView/>
        <TextView android:text="密    码:" 
            android:id="@+id/textView2" 
            android:textSize="24px" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"/>
        <EditText android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:textSize="24px" 
            android:id="@+id/editText2" 
            android:inputType="textPassword"/>
        <TextView />
    </TableRow>
    <!-- 第3行 -->
    <TableRow android:id="@+id/tableRow3" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView/>
        <Button android:text="登录" 
            android:id="@+id/button1" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"/>
        <Button android:text="退出" 
            android:id="@+id/button2" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"/>
        <TextView />
    </TableRow>
</TableLayout>

运行结果:
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值