Search code examples
androidandroid-coordinatorlayoutandroid-appbarlayout

Scroll range of CoordinatorLayout


I am trying to figure out how to have CoordinatorLayout scrolling range to be not screen height. My layout structure is following:

CoordinatorLayout

-- AppBarLayout

---- CollapsingToolbarLayout (scrollflags: scroll)

------ Toolbar (CollapseMode: parallax)

----- /CollapsingToolbarLayout

-- /AppBarLayout

-- NestedScrollView (Behaviour: appbar_scrolling_view_behavior)

-- /NestedScrollView

/ CoordinatorLayout

Even when NestedScrollView child height is like 100dp it can be scrolled all the way top when the content should not be scrollable at all.

Is there a way to affect the scroll range of CoordinatorLayout that if the child content is scrollable it will scroll and only the range that the height is.

I am also seeing this issue when child is RecyclerView and it has e.g. 1 50dp height child -> it should not scroll at all in this case, but when child count gets bigger it should then scroll.

Thanks.


Solution

  • Using AppBarLayout.ScrollingViewBehavior from below link fixes the issue with NestedScrollView

    https://github.com/natario1/ConstrainedScrollBehavior/blob/master/ConstrainedScrollBehavior.java