i am building an android app which is using RecyclerView. I want to add dividers to RecyclerView, which I did using this code:
Divi
Here is a simple Kotlin code snippet to implement ItemDecoration with RecyclerView:
recyclerView.addItemDecoration(object : RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
outRect.left = 20 // Left Margin.
outRect.right = 20 // Right Margin.
outRect.top = 16 // Top Margin.
outRect.bottom = 16 // Bottom Margin.
}
})
Explantation:- In the above example code, we are adding margins to each item of RecyclerView from all four directions.
Happy Coding...