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"

相关推荐
海天鹰13 分钟前
安卓相机:获取最近拍摄的照片缩略图做相册按钮图标
android
tongyiixiaohuang18 分钟前
技术案例分享:金蝶云星空客户数据同步到MySQL的实现
android·数据库·mysql
小羊子说33 分钟前
Android ANR 原理浅析
android·性能优化·车载系统
Be for thing1 小时前
Android Studio 常用快捷键总结
android·学习
Vect__2 小时前
MySQL的数据类型和约束
android·数据库·mysql
ChoSeitaku2 小时前
5.MySQL表的约束|空属性|默认值|列描述|主键|自增长|唯一键|外键
android·数据库·mysql
茅盾体3 小时前
React Native
android·react native·react.js
是Yu欸3 小时前
SGLang 推理服务基础性能评测
android·数据库·大模型·github·昇腾·sglang·qwen3
小菜同学爱学习4 小时前
突破瓶颈!MySQL高级优化与企业级实战场景详解
android·数据库·mysql
casual_clover4 小时前
【Android】创建带参数的 Fragment
android·带参数的fragment