Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll listener - first distanceY always negative for downward scroll?

Tags:

android

I've got a GestureDetector.OnGestureListener hooked up to a ListView. I'm trying to listen for scroll events when the user is scrolling down:

private GestureDetector.OnGestureListener mOnGesture = new GestureDetector.OnGestureListener() {
    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    }
}

But I see a very strange stream of "distanceY" values:

distanceY: -417.02252  // <-- huh?
e1: null
e2: MotionEvent{4097ac08 action=2 x=233.6657 y=417.02252 pressure=0.79999995 size=0.33333334}

distanceY: 1.5640259
e1: null
e2: MotionEvent{4097ac08 action=2 x=233.6657 y=415.4585 pressure=0.79999995 size=0.33333334}

distanceY: 1.5640259
e1: null
e2: MotionEvent{4097ac08 action=2 x=233.6657 y=413.89447 pressure=0.79999995 size=0.40000004}

... rest of values are positive, as expected ...

The first "distanceY" value is negative (unexpected), but then subsequent ones are all positive. What could explain this? I can reproduce this behavior each time.

Thanks

like image 954
user291701 Avatar asked Nov 13 '22 22:11

user291701


1 Answers

distanceY is the distance between current and previous onScroll event. Since this is the first such event I'm assuming it starts calculating from zero.

distanceY: ____-417.02252____  // Same value as...
e1: null
e2: MotionEvent{4097ac08 action=2 x=233.6657 y=____417.02252____ // ...here...
like image 124
harism Avatar answered Nov 15 '22 12:11

harism