TableLayout1

从字面上来看,TableLayout也比较简单,关键是要对相关的属性要熟悉,先看一个简单的例子(后面为效果图):
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="0,1,2"
    android:shrinkColumns="1,2"
    >
   
    <TextView
        android:text="Table Test"
        android:gravity="center"/>
    <TableRow>
        <TextView
            android:layout_column="1"
            android:text="姓名"
            android:gravity="center"/>
        <TextView
            android:text="基本信息"
            android:gravity="center"/>
    </TableRow>
    <TableRow>
        <TextView
            android:text=" 1 "
            android:gravity="center"/>
        <TextView
            android:text="hoyah"
            android:gravity="left"/>
        <TextView
            android:text="Wuhan University"
            android:gravity="right"/>
    </TableRow>
    <TableRow>
        <TextView
            android:text=" 2 "
            android:gravity="center"/>
        <TextView
            android:text="Google"
            android:gravity="left"/>
        <TextView
            android:text="hello Google"
            android:gravity="right"/>
    </TableRow>
    <TableRow>
        <TextView
            android:text="3"
            android:gravity="center"/>
        <TextView
            android:text="Android"
            android:gravity="left"/>
        <TextView
            android:text="Android OS"
            android:gravity="right"/>
    </TableRow>
</TableLayout>

布局讲解:
    android:collapse="1
隐藏该TableLayout里的TableRow的列1,即第2列(从0开始计算),若有多列要隐藏,用“,”隔开。
    android:stretchColumns="0,1,2"
设置列0、1、2为可伸展列。
    android:shrinkColumns="1,2"
设置列1、2为可收缩列。
    android:background="@drawable/picture_name"
本例中没有涉及此属性,它是要设置当前view 的背景图片,图片文件应该放在res文件夹下。

接着我们再看看android官方文档中给出的例子:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">

    <TableRow>
        <TextView
            android:layout_column="1"
            android:text="Open..."
            android:padding="3dip" />
        <TextView
            android:text="Ctrl-O"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>

    <TableRow>
        <TextView
            android:layout_column="1"
            android:text="Save..."
            android:padding="3dip" />
        <TextView
            android:text="Ctrl-S"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>

    <TableRow>
        <TextView
            android:layout_column="1"
            android:text="Save As..."
            android:padding="3dip" />
        <TextView
            android:text="Ctrl-Shift-S"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>

    <View
        android:layout_height="2dip"
        android:background="#FF909090" />

    <TableRow>
        <TextView
            android:text="X"
            android:padding="3dip" />
        <TextView
            android:text="Import..."
            android:padding="3dip" />
    </TableRow>

    <TableRow>
        <TextView
            android:text="X"
            android:padding="3dip" />
        <TextView
            android:text="Export..."
            android:padding="3dip" />
        <TextView
            android:text="Ctrl-E"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>

    <View
        android:layout_height="2dip"
        android:background="#FF909090" />

    <TableRow>
        <TextView
            android:layout_column="1"
            android:text="Quit"
            android:padding="3dip" />
    </TableRow>
</TableLayout>
效果图如下,大家可以上机调试一下:

[img]http://dl.iteye.com/upload/attachment/446459/a8929485-5d84-3f5f-adf8-7298dbef3214.jpg[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值