Pro Android学习笔记(二八):用户界面和控制(16):GridLayout

网格布局:GridLayout

我个人觉得GridLayout的设计还不很完善,每个网格的大小,由填充的cell决定,即默认是wrap很容易整个GridLayout超出屏幕。下面是一个例子:

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:orientation="vertical"
    android:rowCount="4"
    android:columnCount="2"> <!-- 设计4×2的表格 -->
    <ImageView android:layout_row="0"
       android:layout_column="1"
        android:scaleType="fitCenter"
        android:src="@drawable/png02"/> <!-- 可以指定放置的位置 -->
    <ImageView android:layout_row="1"
       android:layout_column="0"
        android:scaleType="fitCenter"
        android:src="@drawable/png04"/>
    <ImageView android:layout_row="2"
        android:layout_column="1"

        android:scaleType="fitCenter"
        android:src="@drawable/png08"/>
    <ImageView android:layout_row="3"
        android:layout_column="0"
        android:scaleType="fitCenter"
        android:src="@drawable/png18"/>
</GridLayout>

GridLayout的灵活支出在于可以指定view方式的位置,运行有些问题不放置内容,如上面的例子。行号和列号均从0开始计算。此外,如果一个cell需要占据多个位置,可以用android:layout_rowspan和android:layout_columnspan来设置。

GridLayout最大的问题就是整个表格的所占空间不确定,行距由该行中最大的cell的高度决定,列距由该列最宽的cell决定。在上面的例子中,有部分控件超出了屏幕。每个cell的大小缺省为wrap_content,如果我们设置为match_parent,则该cell的大小为整屏。

相关链接: 我的Android开发相关文章

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值