I have a custom class to use offsets inside my RecyclerView.
class SpacesItemDecoration(private var space: Int) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
super.getItemOffsets(outRect, view, parent, state)
outRect.bottom = space
}
}
Then I set the offsets in my code like that:
addItemDecoration(SpacesItemDecoration(25))
It works, but it sets the offsets in pixels. How am I supposed to use dp instead of pixels? And why Google preferred using pixels here? It already should be deprecated.