greywolf82 greywolf82 - 1 year ago 144
Android Question

Detect start scroll and end scroll in recyclerview

I need to detect the start/end and direction of scroll in a recyclerview. The scroll listener has two methods:

. The first method is called after the scroll is started (indeed is called onScrolled() and not onScrolling()). The second method gives information about the state but I don't have the direction information. How can I achieve my goal?

Answer Source

See the documentation for onScrollStateChanged(int state). The three possible values are:

  • SCROLL_STATE_IDLE: No scrolling is done.
  • SCROLL_STATE_DRAGGING: The user is dragging his finger on the screen (or it is being done programatically.
  • SCROLL_STATE_SETTLING: User has lifted his finger, and the animation is now slowing down.

So if you want to detect when the scrolling is starting and ending, then you can create something like this:

public void onScrollStateChanged(int state) {
    boolean hasStarted = state == SCROLL_STATE_DRAGGING;
    boolean hasEnded = state == SCROLL_STATE_IDLE;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download