Created
July 6, 2022 17:45
-
-
Save hishd/73b9edfbe9e50c36d17c3aa4b09a8e01 to your computer and use it in GitHub Desktop.
RecyclerView Item Decorator in Kotlin
This file contains hidden or 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
class ItemOffsetDecoration( | |
val context: Context, | |
@DimenRes | |
var top: Int, | |
@DimenRes | |
var bottom: Int, | |
@DimenRes | |
var left: Int, | |
@DimenRes | |
var right: Int | |
): RecyclerView.ItemDecoration() { | |
init { | |
this.top = context.resources.getDimensionPixelSize(top) | |
this.bottom = context.resources.getDimensionPixelSize(bottom) | |
this.left = context.resources.getDimensionPixelSize(left) | |
this.right = context.resources.getDimensionPixelSize(right) | |
} | |
override fun getItemOffsets( | |
outRect: Rect, | |
view: View, | |
parent: RecyclerView, | |
state: RecyclerView.State | |
) { | |
super.getItemOffsets(outRect, view, parent, state) | |
outRect.set(left, top, right, bottom) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment