Skip to content

Instantly share code, notes, and snippets.

@cmorigaki
Created May 24, 2020 21:08
Show Gist options
  • Save cmorigaki/d402403e3443cfefce11b071b9c0006d to your computer and use it in GitHub Desktop.
Save cmorigaki/d402403e3443cfefce11b071b9c0006d to your computer and use it in GitHub Desktop.
Margin Item Decoration (Simple)
class MarginItemDecoration(private val spaceSize: Int) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(
outRect: Rect, view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
with(outRect) {
if (parent.getChildAdapterPosition(view) == 0) {
top = spaceSize
}
left = spaceSize
right = spaceSize
bottom = spaceSize
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment