Saturday, December 28, 2013

VelocityTracker, track the velocity of touch events

It's a example of using Android's VelocityTracker. It's a helper for tracking the velocity of touch events, for implementing flinging and other such gestures. Use obtain() to retrieve a new instance of the class when you are going to begin tracking. Put the motion events you receive into it with addMovement(MotionEvent). When you want to determine the velocity call computeCurrentVelocity(int) and then call getXVelocity(int) and getYVelocity(int) to retrieve the velocity for each pointer id.

1 comment:

And how do you use it? Just printing the values the VelocityTracker computes can hardly be called "usage". Without providing a clear example of how the VelocityTracker can be used in practice this post is useless.