Last active
December 16, 2021 21:01
-
-
Save wassim93/c1fb0b59235f2a2bb34e5e2f90dcef1c to your computer and use it in GitHub Desktop.
Adding item decorator class to set space between recycler view items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create a new class for the custom decorator | |
class MarginItemDecorator(private val horizontalSpacing:Int , private val verticalSpacing:Int) : RecyclerView.ItemDecoration() { | |
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) { | |
super.getItemOffsets(outRect, view, parent, state) | |
outRect.right = horizontalSpacing | |
outRect.left = horizontalSpacing | |
outRect.top = verticalSpacing | |
outRect.bottom = verticalSpacing | |
} | |
} | |
// call in your activity or fragment | |
recycler_list.addItemDecoration(MarginItemDecorator(5,5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment