Thursday 8 January 2015

How to use VelocityTracker to handle touch screen ?

* Android provides a class to help handle touch screen sequences,and that class is VelocityTracker.

* When a finger is in motion on a touch screen,it might be nice to know how fast it is moving 
across the surfaces.

* For Example, if the user is dragging an object across the screen and lets go,your application 
probably wants to show that object flying across the screen accordingly.

* Android provides VelocityTracker to help with the math involved.

* To use VelocityTracker, you first get an instance of a VelocityTracker by calling the static method
VelocityTracker.obtain().

* You can then add MotionEvent objects to it with the addMovement(MotionEvent ev) method.

* You would call this method in your handler that receives MotionEvent objects,from a handler 
method such as onTouch(),or from a view's onTouchEvent().

* The VelocityTracker uses the MotionEvent objects to figure out what is going on with the user's
touch sequence.

* Once VelocityTracker has at least two MotionEvent objects in it.

* The two VelocityTracker methods- getXVelocity() and getYVelocity() - return the corresponding velocity of the finger in the X and Y directions.

No comments:

Post a Comment