Android onScroll - determining the vector of the scroll event

If you implement the GestureDetector.OnGestureListener interface, and make use of the GestureDetector to parse through the touch events, it will tell you when (it thinks) a scroll is happening, and it will call your onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) method.

I wanted to know what the vector was of the scroll - that is, the vector with initial point at the previous scroll location, and its endpoint at the current scroll location (which is where the finger would be).

Looking at the source for GestureDetector (method onTouchEvent), this vector seems to be the following

Vector = (distanceX + e2.getX(), distanceY + e2.getY()) to (e2.getX(), e2.getY())

This seems a little backwards to how I was thinking it would be, but whatever.  Having the source means I can just look and see what they are really doing.  I have no idea how accurate the float pixel values are.

As for e1, I think they are giving you information about the original event that started the scroll with the e1 argument, which I assume is useful in some cases.

Popular Posts