Search code examples
androidandroid-coordinatorlayoutandroid-appbarlayout

CoordinatorLayout Collapse or Expand AppBar on scroll end


Is there a way to move the AppBar up or down, based of percentage of view collapsable view visible when the scroll ends. In the CheeseSquare app, the Toolbar can get stuck in between when scroll ends.

Thanks


Solution

  • That's the exact use case of SCROLL_FLAG_SNAP:

    Upon a scroll ending, if the view is only partially visible then it will be snapped and scrolled to it's closest edge. For example, if the view only has it's bottom 25% displayed, it will be scrolled off screen completely. Conversely, if it's bottom 75% is visible then it will be scrolled fully into view.

    Which was added in version 23.1 of the Android Support Library.

    You can also use it via XML:

    <android.support.v7.widget.Toolbar
        app:layout_scrollFlags="scroll|enterAlways|snap" />