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>
相关推荐
移动开发者1号2 小时前
使用 Android App Bundle 极致压缩应用体积
android·kotlin
移动开发者1号2 小时前
构建高可用线上性能监控体系:从原理到实战
android·kotlin
ii_best7 小时前
按键精灵支持安卓14、15系统,兼容64位环境开发辅助工具
android
美狐美颜sdk7 小时前
跨平台直播美颜SDK集成实录:Android/iOS如何适配贴纸功能
android·人工智能·ios·架构·音视频·美颜sdk·第三方美颜sdk
恋猫de小郭12 小时前
Meta 宣布加入 Kotlin 基金会,将为 Kotlin 和 Android 生态提供全新支持
android·开发语言·ios·kotlin
aqi0012 小时前
FFmpeg开发笔记(七十七)Android的开源音视频剪辑框架RxFFmpeg
android·ffmpeg·音视频·流媒体
androidwork14 小时前
深入解析内存抖动:定位与修复实战(Kotlin版)
android·kotlin
梦天201514 小时前
android核心技术摘要
android
szhangbiao16 小时前
“开发板”类APP如果做屏幕适配
android
高林雨露17 小时前
RecyclerView中跳转到最后一条item并确保它在可视区域内显示
android