10 GridView 样式属性

GridView 样式属性:
1,android:numColumns=”auto_fit” 显示的列数
如果android:numColumns不设置那么自动每行1列
如下图
这里写图片描述
2,auto_fit:自适应 根据item的宽度和手机屏幕的宽度 来决定一行有多少item
3,android:verticalSpacing=”10dp” 行和行之间的距离
代码

<GridView
android:id="@+id/gv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="10dp"
android:numColumns="3"
/>

这里写图片描述

4,android:horizontalSpacing=”10dp” 列与列之间距离
代码:

<GridView
android:id="@+id/gv"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:horizontalSpacing="10dp"
android:numColumns="3"
/>

如下图:

这里写图片描述
5,android:stretchMode=”spacingWidth”:分配剩余部分
spacingWidth:将剩余部分分配给列与列之间空格部分
如果不设置android:columnWidth或者为0那么将全部空间
都填充为间隔
这里写图片描述
我们设置 android:columnWidth=”60dp”
代码:

<GridView
android:id="@+id/gv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchMode="spacingWidth"
android:numColumns="3"
android:columnWidth="60dp"
/>

这里写图片描述
columnWidth:将剩余部分分配给 列

spacingWidthUniform:将剩余部分分配给列与列之间空格部分 还有列与屏幕
代码:

<GridView
android:id="@+id/gv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchMode="spacingWidthUniform"
android:numColumns="3"
android:columnWidth="60dp"
/>

这里写图片描述

转载于:https://www.cnblogs.com/muyuge/p/6152219.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值