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>
相关推荐
androidwork5 小时前
Android LinearLayout、FrameLayout、RelativeLayout、ConstraintLayout大混战
android·java·kotlin·androidx
每次的天空5 小时前
Android第十三次面试总结基础
android·面试·职场和发展
wu_android5 小时前
Android 相对布局管理器(RelativeLayout)
android
李斯维7 小时前
循序渐进 Android Binder(二):传递自定义对象和 AIDL 回调
android·java·android studio
androidwork7 小时前
OkHttp 3.0源码解析:从设计理念到核心实现
android·java·okhttp·kotlin
像风一样自由8 小时前
【001】frida API分类 总览
android·frida
casual_clover8 小时前
Android 之 kotlin 语言学习笔记四(Android KTX)
android·学习·kotlin
移动开发者1号10 小时前
Android 大文件分块上传实战:突破表单数据限制的完整方案
android·java·kotlin
移动开发者1号10 小时前
单线程模型中消息机制解析
android·kotlin
每次的天空12 小时前
Android第十五次面试总结(第三方组件和adb命令)
android