android 两列网格布局,Visual Studio 开发安卓之布局-网格布局(GridLayout)

GridLayout 与 TableLayout 用法非常相似,不过它的“单元格”可以跨行,没有了 Row 子元素,代码更简洁,还有据说它渲染速度比 TableLayout 快。

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:rowCount="3"

android:columnCount="3">

android:text="行1列1" />

android:text="行1列2" />

android:text="跨行"

android:layout_rowSpan="2"

android:layout_gravity="fill" />

android:text="跨列"

android:layout_columnSpan="2"

android:layout_gravity="fill" />

android:text="行3列2"

android:layout_row="2"

android:layout_column="1" />

效果如下:

a0f0ae00111b95627c8ced6b010508c8.png

GridLayout 核心属性:rowCount、columnCount

GridLayout 没有像 TableLayout 一样跟 TableRow,而是直接跟控件。

“单元格”核心属性:layout_rowSpan、layout_columnSpan、layout_gravity、layout_row、layout_column。

注意:GridLayout 的 layout_width 为 wrap_content,否则里面 layout_gravity="fill" 的元素可能不会与周边的元素对齐,它可能会宽些或高些。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值