Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

android - GridView行外页边距(GridView rows outer margin)

I cannot find out a way to add an outer margin to the GridView rows.

(我找不到一种向GridView行添加外边距的方法。)

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.

(我发现了setHorizontalSpacingsetVerticalSpacing属性,它们在GridView行之间添加了内部填充,但是不适用于行的外部边界。)

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

(我想得到一个结果,因为它在Google Play商店中得到了推荐:)

在此处输入图片说明

Thanks!

(谢谢!)

  ask by Diego Acosta translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

(您可以使用android:clipToPadding=false添加滚动项目时不会保留的填充。)

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!

(如果您希望滚动条位于填充区域的外部,请设置android:scrollbarStyle="outsideOverlay"谢谢@Karl!)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...