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>
相关推荐
2501_915106327 小时前
Xcode 上传 ipa 全流程详解 App Store 上架流程、uni-app 生成 ipa 文件上传与审核指南
android·macos·ios·小程序·uni-app·iphone·xcode
消失的旧时光-19437 小时前
Kotlinx.serialization 使用讲解
android·数据结构·android jetpack
灿烂阳光g8 小时前
SELinux 策略文件编写
android·linux
.豆鲨包8 小时前
【Android】Viewpager2实现无限轮播图
android·java
xiangxiongfly9158 小时前
Android CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout实现折叠置顶效果
android·折叠
柿蒂9 小时前
从if-else和switch,聊聊“八股“的作用
android·java·kotlin
Jerry10 小时前
Compose 5 个简短动画,让您的应用脱颖而出
android
PenguinLetsGo11 小时前
你的App是否有出现过幽灵调用?
android
没有了遇见11 小时前
Android ViewPager2 嵌套 RecyclerView 滑动冲突解决方案
android
咖啡の猫11 小时前
Android开发-选择按钮
android·gitee