Doist / RecyclerViewExtensions

RecyclerView made easier.
MIT License
493 stars 42 forks source link

Sticky header showing below item #24

Closed FilippoVigani closed 6 years ago

FilippoVigani commented 6 years ago

I'm using the Sticky Header to get a specific header to show, both the items and the header are bound to a view using android databinding. The issue I'm facing is that when a header sticks to the top, the items overlap it instead of sliding below it. Any ideas what the issue could be?

FilippoVigani commented 6 years ago

I managed to solve it by extending the provided StickyHeaders.ViewSetup and implementing its members like below:


override fun setupStickyHeaderView(stickyHeader: View?) {
    stickyHeader?.translationZ = context.resources.getDimension(R.dimen.header_elevation)
}
override fun teardownStickyHeaderView(stickyHeader: View?) {
    stickyHeader?.translationZ = 0f
}
goncalossilva commented 6 years ago

That's a good approach. Given how Android renders views, if your sticky header is before other views, other views will be drawn on top of it... Unless you change drawing order explicitly (eg. via elevation).