How can I acheive such behavior for bottom bar? It works like scroll aware behavior for floating action button but when the recyckerview scrolls to the bottom, then it pulls that panel up (like the last element in the recyclerview is that panel). I don't think that the developer duplicated those views. Maybe it is possible to extend behavior somehow?
Here is the code for scroll aware behavior:
class ScrollAwareBehavior : CoordinatorLayout.Behavior<View> {
constructor() : super()
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout?, child: View?, directTargetChild: View?, target: View?, nestedScrollAxes: Int): Boolean {
return nestedScrollAxes==ViewCompat.SCROLL_AXIS_VERTICAL
}
override fun onNestedScroll(coordinatorLayout: CoordinatorLayout?, child: View?, target: View?, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int) {
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed)
if (dyConsumed > 0) {
val layoutParams = (child?.layoutParams as? CoordinatorLayout.LayoutParams?)?:return
val fab_bottomMargin = layoutParams.bottomMargin
child?.animate()?.translationY(child.height.toFloat() + fab_bottomMargin)?.setInterpolator(AccelerateDecelerateInterpolator())?.start()
} else if (dyConsumed < 0) {
child?.animate()?.translationY(0f)?.setInterpolator(AccelerateDecelerateInterpolator())?.start()
}
}
}
One way of doing that it's to listen the scroll event on the RecyclerView
and check the last visible item and check if it's the last one.
For that, there is findLastCompletelyVisibleItemPosition()
in LinearLayoutManager
and getItemCount()
in Adapter
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.