GridView 提供这么两个方法 setHorizontalSpacing(int)
和 setVerticalSpacing(int)
。 API 的 DOC 如下:
设置水平间距,这里的单位是 px。
public void setHorizontalSpacing(int horizontalSpacing)
Set the amount of horizontal (x) spacing to place between each item in the grid.Parameters:horizontalSpacing The amount of horizontal space between items, in pixels. @attr ref android.R.styleable#GridView_horizontalSpacing
设置垂直间距。
public void setVerticalSpacing(int verticalSpacing)
Set the amount of vertical (y) spacing to place between each item in the grid.Parameters:verticalSpacing The amount of vertical space between items, in pixels.@attr ref android.R.styleable#GridView_verticalSpacing
注意:这里设置的是 item 之间的间隔, space between items.
- EOF -
本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处,尊重他人劳动。
转载请注明:文章转载自 Binkery 技术博客 [https://binkery.com]
本文标题: GridView 设置 item 水平间距和垂直间距的方法
本文地址: https://binkery.com/archives/2020.08.27-android-gridview-horizontal-vertical-space.html