I have RecyclerView and I need next behavior:
The selected answer is flawed. I already commented on it and explained why so. You may want to read that if your interested.
So if the selected answer is wrong, whats a different better way to solve this?
1) Create you layout like so:
<-- This is your footer and it can be anything you want -->
2) Set the height of your footer as bottomPadding of your RecyclerView
. It is crucial to do on preDraw
so you can have the proper height or size of yur footer.
view.doOnPreDraw {
val footerheight = yourFooter.height
recyclerView.updatePadding(bottom = footerHeight)
...
}
3) Now all you need to do is to listen to recyclerview scroll and listen when you need to translate you footer at the correct time. So do something like:
view.doOnPreDraw {
val footerheight = yourFooter.height
recyclerView.updatePadding(bottom = footerHeight)
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
val range = recyclerView.computeVerticalScrollRange()
val extent = recyclerView.computeVerticalScrollExtent()
val offset = recyclerView.computeVerticalScrollOffset()
val threshHold = range - footerHeight
val currentScroll = extent + offset
val excess = currentScroll - threshHold
yourFooter.transalationX = if (excess > 0)
footerHeight * (excess.toFloat()/footerHeight.toFloat()) else 0F
}
})
}
Hope this would be helpful to someone in the future.