[Learning summary] 2, Android Velocitytracker (acquisition rate of the class)

Source: Internet
Author: User

Reference: http://blog.jrj.com.cn/4586793646,5298605a.html thanks to this brother!

Android.view.VelocityTracker The main use is to track the rate of touch screen events (flinging events and other gestures gesture events) and to do some effects for up after.

1, Use the obtain () function to obtain an instance of the class.

2, some of the commonly used methods:

2.1, using the Addmovement (Motionevent event) function to pass the current move event to the Velocitytracker object, the parameter is the event object.

2.2, use the computecurrentvelocity (int units) function to calculate the current speed parameter units: The rate you use for Unit 1 means that the rate of how many pixels are moving in a millisecond, 1000 for one second

How many pixels are moving in time. The unit is in milliseconds.

2.3,computecurrentvelocity(int units, float maxvelocity) parameter 1 ibid., Parameter maxvelocity: This method can calculate the maximum rate of events. If the calculated rate is greater than maxvelocity

The resulting rate is maxvelocity, less than maxvelocity is the true rate of computation.

Example: Currentvelocity =currentvelocity>maxvelocity?maxvelocity:currentvelocity;

2.4, using getxvelocity (), getyvelocity () function to get the current horizontal and vertical speed

3, Example Demo:

  

1 PrivateVelocitytracker Mvelocitytracker;//Life Variables2         3         //In the ontouchevent (motionevent ev)4 5 6         if(Mvelocitytracker = =NULL) { 7Mvelocitytracker = Velocitytracker.obtain ();//get Velocitytracker class instances8         } 9Mvelocitytracker.addmovement (EV);//adding events to an instance of the Velocitytracker classTen  One  A         //determine when EV events are motionevent.action_up: Calculation rate -         FinalVelocitytracker Velocitytracker =Mvelocitytracker; -         //provides pixels per second theVelocitytracker.computecurrentvelocity (1, (float) 0.01);//When setting the Maxvelocity value to 0.1, the rate is greater than 0.01, the display rate is 0.01, the rate is less than 0.01, the display is normal -LOG.I ("Test", "Velocitytraker" +velocitytracker.getxvelocity ());  -                                  -Velocitytracker.computecurrentvelocity (1000);//set the value of units to 1000, which means how many pixels are moving in a second time +LOG.I ("Test", "Velocitytraker" +velocitytracker.getxvelocity ());

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.