Skip to content

Instantly share code, notes, and snippets.

@hishd
Created July 6, 2022 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hishd/73b9edfbe9e50c36d17c3aa4b09a8e01 to your computer and use it in GitHub Desktop.
Save hishd/73b9edfbe9e50c36d17c3aa4b09a8e01 to your computer and use it in GitHub Desktop.
RecyclerView Item Decorator in Kotlin
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