Android布局【TableLayout】

文章目录

说明

TableLayout也称为表格布局

常见属性

  1. android:collapseColumns:设置需要被隐藏的列的序列号,从0开始
  2. android:stretchColumns:设置允许被拉伸的列的列序号,从0开始,拉伸占据的是剩余的空间
  3. android:shrinkColumns:设置允许被收缩的列的列序号,从0开始

子控件设置属性

  1. android:layout_column:显示在第几列
  2. android:layout_span:横向跨几列

项目结构

主要代码

activity_main.xml

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="4"
    android:stretchColumns="1">

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

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

    <TableRow>

        <Button
            android:layout_column="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮0" />

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

    </TableRow>

    <TableRow>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮0" />

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

        <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="按钮3" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮4" />

    </TableRow>

    <TableRow>
        <Button
            android:layout_column="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮0"/>

        <Button
            android:layout_column="3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮1"/>

    </TableRow>


</TableLayout>
相关推荐
Dingdangr4 小时前
Android中的Intent的作用
android
技术无疆4 小时前
快速开发与维护:探索 AndroidAnnotations
android·java·android studio·android-studio·androidx·代码注入
GEEKVIP4 小时前
Android 恢复挑战和解决方案:如何从 Android 设备恢复删除的文件
android·笔记·安全·macos·智能手机·电脑·笔记本电脑
Jouzzy11 小时前
【Android安全】Ubuntu 16.04安装GDB和GEF
android·ubuntu·gdb
极客先躯11 小时前
java和kotlin 可以同时运行吗
android·java·开发语言·kotlin·同时运行
Good_tea_h13 小时前
Android中的单例模式
android·单例模式
计算机源码社18 小时前
分享一个基于微信小程序的居家养老服务小程序 养老服务预约安卓app uniapp(源码、调试、LW、开题、PPT)
android·微信小程序·uni-app·毕业设计项目·毕业设计源码·计算机课程设计·计算机毕业设计开题
丶白泽19 小时前
重修设计模式-结构型-门面模式
android
晨春计20 小时前
【git】
android·linux·git
标标大人21 小时前
c语言中的局部跳转以及全局跳转
android·c语言·开发语言