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