Atalyk
Atalyk

Reputation: 525

Detect scroll end in android.widget.Scroller

I would like to detect when a user stops scrolling using android.widget.Scroller based on onTouchEvent checking MotionEvent.ACTION_UP. When the user scrolls once it works fine but when the user scrolls quickly to reach particularly position it shows that the user scrolled many times though I want to detect it as one scroll. How can I achieve that?

@Override
public boolean onTouchEvent(MotionEvent event) {
    if(event.getAction() == MotionEvent.ACTION_UP) {
      if(mIsScrolling) {
        mIsScrolling = false;
        //
      }
    }
    mScaleDetector.onTouchEvent(event);
    return mGestureDetector.onTouchEvent(event);
}

Upvotes: 2

Views: 101

Answers (1)

Jayanth
Jayanth

Reputation: 6287

you can do this by simple math

getCurrX(), getCurrY() methods returns current offset position x and y of scroller respectively

similarly

getFinalX(), getFinalY() methods returns current offset positions x and y of scroller respectively

so

if(getCurrY() == getFinalY()) // true means you reached end of the scroller

for reference the doc here Scroller

Upvotes: 1

Related Questions