Android XML 布局基础(八)帧布局 - GridLayout

| android:layout_rowSpan="数字" | 占用一列的几个行位置 |

| android:layout_columnWeight="数字" | 该控件的列权重,与 android:layout_weight 类似,例如有 GridLayout 上两列,都设置 android:layout_columnWeight = "1",则两列各占 GridLayout 宽度的一半 |

| android:layout_rowWeight="数字" | 跟 layout_columnWeight 同理 |

二、案例


<?xml versi on="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<GridLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:columnCount="4"

android:rowCount="6"

tools:ignore="MissingConstraints">

<View

android:layout_width="80dp"

android:layout_height="80dp"

android:background="#ffc"/>

<View

android:layout_width="80dp"

android:layout_height="80dp"

android:background="#fcf"/>

<View

android:layout_width="80dp"

android:layout_height="80dp"

android:background="#cff"/>

<View

android:layout_width="80dp"

android:layout_height="80dp"

android:background="#ccc"/>

<View

android:layout_rowSpan="2"

android:layout_width="80dp"

android:layout_height="160dp"

android:background="#ddd"/>

<View

android:layout_rowSpan="2"

android:layout_width="80dp"

android:layout_height="160dp"

android:background="#cdc"/>

<View

android:layout_columnSpan="2"

android:layout_width="160dp"

android:layout_height="80dp"

android:background="#f88"/>

<View

android:layout_columnSpan="2"

相关推荐
二流小码农3 小时前
鸿蒙开发:证书只能创建3个,第4个应用怎么办
android·ios·harmonyos
阿杰m5 小时前
Android源码第十七章:PowerManager 与后台任务——锁屏后怎么跑?
android
JMchen1235 小时前
【Android 性能优化实战 60 讲】10 Jetpack App Startup 内核魔改:手写异步懒加载启动框架,根治串行初始化耗时
android·性能优化·源码分析·启动优化·kotlin协程·app startup
2601_967980116 小时前
python+appium自动化测试如何控制App的启动和退出
android·自动化测试·python·appium·设备调试
booboosui7 小时前
不写安装器:点一下就往对话里塞 152 个字符
android
一条破秋裤8 小时前
【1117】【内存资源管控】【笔记】
android·笔记
AI导出鸭PC端8 小时前
用 AI 导出鸭高效处理:豆包导 pdf 怎么压缩但清晰
android·人工智能·pdf·豆包·ai导出鸭
therese_100869 小时前
流媒体协议RTMP推流demo-安卓端
android
疯华整猫10 小时前
同一个 App,五种手机五种死法:2026 年 Android 五大 ROM 兼容的 8 个真实坑
android·性能优化
疯华整猫10 小时前
别再抄 Flutter 了:2026 年 Android / iOS / 小程序跨端架构选型的四本成本账
android·前端·ios