网格布局

GridLayout(网格布局)

特点:

1、可以自己设置布局中组件的排列方式

2、可以自定义网格布局有多少行,多少列

3、可以直接设置组件位于某行某列

4、可以设置组件横跨几行或者几列

关键的两个属性:

android:rowCount 设置行的个数

android:columnCount 设置列的个数

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:rowCount="4"
android:columnCount="4">
<TextView
android:layout_height="50dp"
android:layout_columnWeight="1"
android:background="#0f0"></TextView>
<TextView
android:layout_height="50dp"
android:layout_columnWeight="1"
android:background="#f0f"></TextView>
<TextView
android:layout_height="50dp"
android:layout_columnWeight="1"
android:background="#ff0"></TextView>
<TextView
android:layout_height="50dp"
android:layout_columnWeight="1"
android:background=""></TextView>
<TextView
android:layout_height="50dp"
android:layout_columnWeight="1"
android:background="#ff0"></TextView>
<TextView
android:layout_height="50dp"
android:layout_columnWeight="1"
android:background="#00f"></TextView>
<TextView
android:layout_height="50dp"
android:layout_columnWeight="1"
android:background="#0f0"></TextView>
</GridLayout>

效果如下:一共被分为8个

posted @   zpchcbd  阅读(283)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
点击右上角即可分享
微信分享提示