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"

相关推荐
SHoM SSER4 分钟前
MySQL 数据库连接池爆满问题排查与解决
android·数据库·mysql
黄林晴4 分钟前
Android 17 取色器 API:无需权限,一行 Intent 跨应用取色
android
程序员陆业聪2 小时前
别再说 Flutter 是唯一选择了——KMP 正在悄悄抢走它的地盘
android
三少爷的鞋2 小时前
2026 已过 1/3:事豫则立,不预则废——关于架构、协程与边界的思考
android
冬奇Lab2 小时前
Android 15 音频子系统(八):Audio HAL 与硬件接口——音频数据的最后一公里
android·音视频开发·源码阅读
黄林晴5 小时前
Compose Multiplatform 1.10 发布:里程碑式更新!
android
流星白龙6 小时前
【MySQL】19.MySQL用户管理
android·mysql·adb
匆忙拥挤repeat6 小时前
Android Compose 可组合项的生命周期、副作用API
android
hnlgzb7 小时前
目前编写安卓app的话有哪几种设计模式?
android·设计模式·kotlin·android jetpack·compose
studyForMokey8 小时前
【Android面试】Fragment生命周期专题
android·microsoft·面试