GridView rows outer margin

好久不见. 提交于 2019-12-03 01:43:06

问题


I cannot find out a way to add an outer margin to the GridView rows. I found the setHorizontalSpacing and setVerticalSpacing properties which add inner padding between the GridView rows, however it doesn't apply to the outer borders of the rows.

I'd like to have a result as it's featured on the Google Play store:

Thanks!


回答1:


You can use android:clipToPadding=false to add padding that doesn't stay when the items are scrolled. Like this

<GridView
    android:id="@+id/grid"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:horizontalSpacing="16dp"
    android:verticalSpacing="16dp"
    android:padding="16dp"
    android:clipToPadding="false" />

And if you want the scrollbar on the outside of the padding area, set android:scrollbarStyle="outsideOverlay" thanks @Karl!




回答2:


If you want result like GooglePlay store, you can set setHorizontalSpacing and setVerticalSpacing and then set layout_margin to GridView.



来源:https://stackoverflow.com/questions/17138943/gridview-rows-outer-margin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!