Last active
June 12, 2019 20:30
-
-
Save JoaquimLey/9aca59bc1f2767a03dd0a82f58e967d8 to your computer and use it in GitHub Desktop.
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
open class RecyclerViewMarginItemDecoration( | |
private val sizeInDp: Int = 16, | |
private val isTop: Boolean = false | |
) : RecyclerView.ItemDecoration() { | |
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) { | |
super.getItemOffsets(outRect, view, parent, state) | |
if (isTop) { | |
if (parent.getChildAdapterPosition(view) == 0) { | |
outRect.top = sizeInDp.toPx() | |
} | |
} else { | |
if (parent.getChildAdapterPosition(view) == state.itemCount - 1) { | |
outRect.bottom = sizeInDp.toPx() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment