Jack
Jack

Reputation: 241

Android Swipe Velocity

What is the best way to compute the speed/velocity of a swipe? Is there some fancy class or function that provides this or do I need to perform this by measuring touch up and touch down? I did some searching but came up empty - perhaps I dont have the right terminology.

Upvotes: 3

Views: 3632

Answers (1)

nhaarman
nhaarman

Reputation: 100438

OnGestureListener has the following method, providing the velocity for the x- and y-axis:

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)

You can implement the OnGestureListener, or, from the docs:

If you want to listen for all the different gestures then implement this interface. If you only want to listen for a subset it might be easier to extend GestureDetector.SimpleOnGestureListener.

Upvotes: 5

Related Questions