Created
September 15, 2018 14:56
-
-
Save amalhanaja/0be229b3612266d95c82d55cb40fd497 to your computer and use it in GitHub Desktop.
ItemOffsetDecorator for RecyclerView
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
class ItemOffsetsDecorator( | |
private val block: (position: Int, count: Int, rect: Rect) -> Unit | |
): RecyclerView.ItemDecoration() { | |
override fun getItemOffsets(outRect: Rect?, view: View?, parent: RecyclerView?, state: RecyclerView.State?) { | |
super.getItemOffsets(outRect, view, parent, state) | |
parent?.getChildAdapterPosition(view)?.run position@ { | |
outRect?.run rect@ { | |
state?.itemCount?.run count@ { | |
block.invoke(this@position, this@count, this@rect) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment