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 小时前
2024年软考中级信息安全工程师|选择题考点+案例分析真题解析(含答案)
android·网络
用户2018792831675 小时前
一文讲透 Android Native Heap 监控原理:一间"只进不出"的仓库,和总部派来的侦探
android
YB13756 小时前
Jetpack Compose 动画animate*AsState
android
高晶6 小时前
Android 通讯录应用开发实战:从零搭建 SQLite 数据持久化完整项目
android·设计模式·前端框架
隐擎fox6 小时前
深入 Android 移动端风控与协议层对抗:内核级虚拟环境检测、网络堆栈特征伪装与住宅 IP 协同实战
android·网络·python·网络协议·tcp/ip
换元不配限8 小时前
从 AsyncTask 到现代并发:Android 异步方案的演进与替代实践
android·asynctask·异步编程·方案对比·asynctask替代方案
用户2018792831678 小时前
你的 App 为什么是「电量刺客」?——从一条 WakeLock 追到 Linux 内核的 Android 省电原理全解
android
mmsx9 小时前
Android 安全校验下沉到原生层:防 patch 与构建期自动化
android·安全·自动化
老牛日常随笔10 小时前
Google把Android测试搬进AI对话:ARTEMIS如何用自然语言操作你的手机
android·人工智能·智能手机