I would like the vertical scroll on the CollapsingToolbarLayout / AppBarLayout ONLY when the scroll/touch event occurs in the nestedscrollview (this is working), but if the user
I wrote a BindingAdapter for nsL's answer:
@BindingAdapter("scrollable")
fun setScrollable(appBarLayout: AppBarLayout, scrollable: Boolean) {
val layoutParams = appBarLayout.layoutParams as CoordinatorLayout.LayoutParams
val behavior = (layoutParams.behavior as? AppBarLayout.Behavior) ?: AppBarLayout.Behavior()
behavior.setDragCallback(object : AppBarLayout.Behavior.DragCallback() {
override fun canDrag(appBarLayout: AppBarLayout): Boolean = scrollable
})
layoutParams.behavior = behavior
}
You can use it in a databinding layout like this:
...
In my case I also wanted to disable the scroll on the NestedScrollView, which is why I wrote a second BindingAdapter:
@BindingAdapter("scrollable")
fun setScrollable(nestedScrollView: NestedScrollView, scrollable: Boolean) {
nestedScrollView.setOnTouchListener { _, _ -> !scrollable }
}