TableLayout 简单的记录

本文详细介绍了TableLayout的基本使用方法及其属性,包括如何设置列的收缩、拉伸和隐藏等特性,并展示了内部控件如Button的具体布局配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

TableLayout 简单的记录

一下是tablelayout的主要的属性:

  • android:shrinkColumns ——-设置可收缩的列
  • android:stretchColumns ——设置可伸展的列
  • android:collapseColumns ——设置要隐藏的列(索引列从0开始)

内部的TableRaw的属性内部控件属性:

  • android:layout_column ——-该单元格在第几列显示
  • android:layout_span ——-该单元格占据列数,默认为1

这里写图片描述

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:shrinkColumns="0,1"
        >
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="我独自站一行"
            />

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0000000000000000000000000"
                />

            <Button android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1111111111111111111111111111111111111"
                />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="22222222222222
                                22222222"
                />

            <Button android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:textAllCaps="false"
                android:text="match_parent"
                />

            <Button android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2"
                />

        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2"
                />

            <Button android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2"

                />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="span=3"
                android:textAllCaps="false"
                android:layout_span="3"
                />

        </TableRow>
    </TableLayout>

    <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:stretchColumns="1"
        >

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2"
                />

            <Button android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAllCaps="false"
                android:text="stretchColumns=1"

                />

        </TableRow>
    </TableLayout>
</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值