TableLayout布局

在TableLayout布局布局中加入按钮,会占据一行,想要多按钮在同一行就需要TableRow,但是超出的部分不会换行,不会显示。
在这里插入图片描述

在这里插入图片描述

常用属性

android:collapseColumns 设置需要被隐藏的列的序号,从0开始
android:stretchColumns 设置允许被拉伸的列的列序号,从0开始
android:shrinkColumns 设置允许被收缩的列的列序号,从0开始

子控件设置属性
android:layout_column 显示在第几列(默认第0列)
android:layout_span 横向跨几列

隐藏
在这里插入图片描述
常用属性中的拉伸,占用的是剩余空间,没有空间就不会被拉伸,这有4个按钮(包括隐藏的那个),5个按钮的话就不会拉伸
在这里插入图片描述
在这里插入图片描述

常用属性中的收缩,需要有按钮超出屏幕, 如果没超出屏幕,不会收缩,由于之前按钮长度正好在边缘,收缩的话相当于隐藏了,所以我更改的按钮的text,让按钮在边界超出一半

收缩前
在这里插入图片描述
收缩后
在这里插入图片描述
在这里插入图片描述

案例代码

activity_main.xml

<?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="1"
    android:layout_column="2"
    >

    <Button
        android:text="第1个按钮"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <Button
        android:text="第2个按钮"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TableRow>
        <Button
            android:text="第1个"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

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

        <Button
            android:text="第3个"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <Button
            android:text="第4个"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <Button
            android:text="第5个"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    </TableRow>

    <TableRow>
        <Button
            android:text="第1个按钮"
            android:layout_column="1"
            android:layout_span="2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <Button
            android:text="第2个按钮"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </TableRow>

</TableLayout>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只小阿大:)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值