ShamylZakariya / StickyHeaders

Adapter and LayoutManager for Android RecyclerView which enables sticky header positioning.
MIT License
1.4k stars 185 forks source link

Vertical Spacing Decorator for Item Views Only #79

Open iad24 opened 6 years ago

iad24 commented 6 years ago

I usually use this decorator to put space between items in a recyclerview:

class ItemVerticalSpaceDecoration(private val space: Int, private val includeTopBottom: Boolean = true) : RecyclerView.ItemDecoration() {

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
        outRect.bottom = space
        if (parent.getChildAdapterPosition(view) == 0 && includeTopBottom) { // if first item
            outRect.top = space
        }
        else if (parent.getChildAdapterPosition(view) == parent.adapter.itemCount - 1 && !includeTopBottom) { // if last item
            outRect.bottom = 0
        }
    }
}

But when I apply here, the section headers will also get the spacing. How to apply only to the item views?