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"

相关推荐
某空m8 分钟前
【Android】Glide的使用
android·glide
QING6188 分钟前
Jetpack Compose 中的 ViewModel 作用域管理 —— 新手指南
android·kotlin·android jetpack
鹏多多15 分钟前
flutter-使用EventBus实现组件间数据通信
android·前端·flutter
ShayneLee81 小时前
Nginx修改请求头响应头
android·运维·nginx
廋到被风吹走1 小时前
【数据库】【MySQL】高可用与扩展方案深度解析
android·数据库·mysql
恋猫de小郭1 小时前
Flutter 官方正式解决 WebView 在 iOS 26 上有点击问题
android·前端·flutter
春蕾夏荷_7282977251 小时前
c++ 将xml数据写入sqlite数据库
xml·数据库
秦奈1 小时前
Unity复习学习随笔(六):XML数据
xml·学习
CaspianSea5 小时前
编译Android 16 TV模拟器(一)
android
廋到被风吹走9 小时前
【数据库】【MySQL】InnoDB外键解析:约束机制、性能影响与最佳实践
android·数据库·mysql