How do you set the column spacing with a RecyclerView using a GridLayoutManager? Setting the margin/padding inside my layout has no effect.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Answers above have clarified ways to set margin handling GridLayoutManager and LinearLayoutManager.
But for StaggeredGridLayoutManager, Pirdad Sakhizada's answer says: "It might not work very well with StaggeredGridLayoutManager". It should be the problem about IndexOfSpan.
You can get it by this way:
Following code works well, and each column has same width:
Usage
1. no edge
2. with edge
This Link worked for me all situations you may try this.
The following is the step-by-step simple solution if you want the equal spacing around items and equal item sizes.
ItemOffsetDecoration
Implementation
In your source code, add
ItemOffsetDecoration
to yourRecyclerView.
Item offset value should be half size of the actual value you want to add as space between items.Also, set item offset value as padding for its
RecyclerView
, and specifyandroid:clipToPadding=false
.Here is my modification of
SpacesItemDecoration
which can take numOfColums and space equally on top, bottom, left and right.and use below code on your logic.
To made https://stackoverflow.com/a/29905000/1649371 (above) solution work I had to modify the following methods (and all subsequent calls)