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>
相关推荐
mmsx2 小时前
Android 新闻资讯客户端实战:从零搭建一个完整的新闻 App
android·app·源码
三8443 小时前
PHP 绕过污点追踪构造 Webshell:反序列化引用复用与 Trait 可变函数 RCE
android
石头猫灯3 小时前
WordPress wp2shell漏洞断点逐过程到注入点
android·学习
Android打工仔4 小时前
Kotlin 协程源码解析(五):BaseContinuationImpl.resumeWith() —— Continuation 链是如何被展开的?
android·kotlin
存在morning5 小时前
【PySpark 学习笔记 三】DataFrame API 入门
android·java·数据库
YSoup5 小时前
2026 安卓面试助手APP(安卓八股、题库)
android·面试·职场和发展
xcyxiner5 小时前
flutter 运行到模拟器上
android·前端·flutter
Android-Flutter5 小时前
android Glide 源码流程分析
android·kotlin
Android-Flutter6 小时前
android Glide 使用详解
android·kotlin
恋猫de小郭6 小时前
Dart 3.13 的到底改了什么?为什么很重要?有什么坑?
android·前端·flutter