1

I am trying to control the scrolling behaviour of snap scroll flag of collpasingtoolbarlayout . According to this tutorial link 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. what I'm trying to achieve is to make the Snap Behaviour works in 1 Direction only from Bottom to Top . which means if that view is close from the top edge and the user is scrolling from the bottom it should work normally in this cause. otherwise, for ex if user scrolling from top to bottom it should do nothing.

Here is a gif of Santa application of Google which I'm trying to achieve the same behaviour .

Gif Link

Joe Seph
  • 11
  • 3
  • 1
    Hi @Joe, did you manage to resolve poor snap configuration for AppBarLayout? I fight with similar problem as you did. – pkleczko Mar 01 '17 at 16:48

1 Answers1

2

Here's a link to a post that was made before the support for the snap scroll flag which includes code that recreates the same behavior. You might be able to modify this custom behavior to fit your needs.

In that code you will find the following section which you need to edit for your "close to top or bottom" logic:

if (topOffset < -(scrollRange / 2f)) {     //Close to top
        // Snap up (to fully invisible)
        animateOffsetTo(-scrollRange);
    } else {                               //Close to bottom
        // Snap down (to fully visible)
        animateOffsetTo(0);
    }

You will also need to include logic to compare the offset at the start of the scroll to the offset at the stop of teh scroll to determine the swipe direction.

Good luck!

Community
  • 1
  • 1