码迷,mamicode.com
首页 > 其他好文 > 详细

A018-布局之TableLayout

时间:2015-10-05 00:50:28      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:android   布局   

TableLayout

表格布局,顾名思义像表格一样进行布局。我们通常配合TableRow一起使用,TableRow代表一行,有多少个TableRow就有多少行。

eg:三行三列的布局

<?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"
    >
    <TableRow>
        <Button android:text="Button1"/>
        <Button android:text="Button2"/>
        <Button android:text="Button3"/>
    </TableRow>
    <TableRow>
        <Button android:text="Button4"/>
        <Button android:text="Button5"/>
        <Button android:text="Button6"/>
    </TableRow>
    <TableRow>
        <Button android:text="Button7"/>
        <Button android:text="Button8"/>
        <Button android:text="Button9"/>
    </TableRow>
</TableLayout>

XML Attribute

shrinkColumns属性,以0为序,当控件布满布局时,指定列自动填充可用部分。
技术分享

strechColumns属性,以第0行为序,指定列对空白部分进行填充。
技术分享

collapseColumns属性:以0行为序,隐藏指定的列。
技术分享

layout_column属性:以0行为序,设置组件显示指定列。
layout_span属性:以第0行为序,设置组件显示占用的列数。

技术分享

示例代码:

<?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:shrinkColumns="2"
    以0为序,当控件布满布局时,指定列自动填充可用部分。
    strechColumns属性,以第0行为序,指定列对空白部分进行填充
    collapseColumns属性:以0行为序,隐藏指定的列
    -->
    <TableRow>
        <Button android:text="Button1"
            android:layout_span="3"/>
        <Button android:text="Button2"/>
        <Button android:text="Button3"/>
    </TableRow>
    <TableRow>
        <Button android:text="Button4"
            android:layout_column="1"/>
        <Button android:text="Button5"
            />
        <Button android:text="Button6"/>
    </TableRow>
    <TableRow>
        <Button android:text="Button7"/>
        <Button android:text="Button8"
            android:layout_column="2"/>
        <Button android:text="Button9"/>
    </TableRow>
</TableLayout>

转载请注明:IT_xiao小巫 http://blog.csdn.net/wwj_748

版权声明:本文为博主原创文章,未经博主允许不得转载。

A018-布局之TableLayout

标签:android   布局   

原文地址:http://blog.csdn.net/wwj_748/article/details/48899101

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!