As the name implies, rate tracker, mainly used to track the rate of touch events (flinging and getsture), is very useful in the design of UI effects.
When used:
Step1: Instantiated by the Velocitytracker.obtain () method.
Step2: Use Addmovement (motionevent) to specify the detection object.
Step3: The rate at which horizontal sliding is obtained by getxvelocity () (similar vertically).
The mastery of Velocitytracker is the use of several methods inside:
1. public static Velocitytracker obtain ()
Instantiating a Velocitytracker object
Note: Ensure that the Recycle () method is called after the monitoring is finished. Typically, only one active object is maintained to monitor the movement
2. public void Recycle ()
Retract Velocitytracker objects for reuse
Note: The object cannot be used again after this method is called
3. public void Clear ()
Set the rate tracker to the initial state
4. public void Addmovement (motionevent ev)
Add an action event to the tracker
Note: Typically used in Motionevent.action_down, motionevent.action_move, and motionevent.action_up conditions
EV is in, for example, in Ontouchevent (...) The Motionevent type parameter received in
5. public void computecurrentvelocity (int units)
Calculates the rate at which points are currently collected
Note: This method is expensive and prudent to use
6. Getxvelocity () and getxvelocity ()
To get the rate of horizontal and vertical
Note: use computecurrentvelocity (int) to set the rate of time unit
Summary: The use process is generally, instantiation-set monitoring events-set rate unit time-get the vertical to the velocity.
Statement: The article through the Web-based learning and query API Official document Summary, if there is an error place, WAN Wang message exchange.
Android.view.VelocityTracker