Android and android Official Website
VelocityTracker
It is mainly used for touch events. VelocityTracker computes the current speed in real time by tracking a series of events.
Method
// Get a VelocityTracker object. Remember to recycle it after use. // after recycling, it means you do not need to use it. The system assigns this object to other requestors static public VelocityTracker obtain (); public void recycle (); // calculate the current speed. The unit of units indicates, 1 indicates px/millisecond, and 1000 indicates px/second ,.. // maxVelocity the maximum public void computeCurrentVelocity (int units, float maxVelocity) you want for this computing speed ); // after a computeCurrentVelocity operation, you can use the following methods to obtain the calculated value. // id is the ID of the touch point of the touch event to identify multiple touch points, this identifier can be used to ignore/other contact interference during computation. Of course, the interference must be public float getXVelocity (); public float getYVelocity (); public float getXVelocity (int id ); public float getYVelocity (int id );
Code
Public class VelocityTrackerTest extends Activity {private TextView mInfo; private VelocityTracker mVelocityTracker; private int mMaxVelocity; private int mPointerId; @ Override protected void onCreate (Bundle savedInstanceState. onCreate (savedInstanceState); mInfo = new TextView (this); mInfo. setLines (4); mInfo. setLayoutParams (new LayoutParams (LayoutParams. FILL_PARENT, LayoutParams. FILL_PARE NT); mInfo. setTextColor (Color. WHITE); setContentView (mInfo); mMaxVelocity = ViewConfiguration. get (this ). getMaximumFlingVelocity () ;}@ Override public boolean onTouchEvent (MotionEvent event) {if (null = mVelocityTracker) {mVelocityTracker = VelocityTracker. obtain ();} mVelocityTracker. addMovement (event); final VelocityTracker verTracker = mVelocityTracker; switch (event. getAction () {case Motio NEvent. ACTION_DOWN: // obtain the id of the first contact. At this time, there may be multiple contacts, but at least one mPointerId = event. getPointerId (0); break; case MotionEvent. ACTION_MOVE: // obtain the pseudo instantaneous speed of verTracker. computeCurrentVelocity (1000, mMaxVelocity); float velocityX = verTracker. getXVelocity (mPointerId); float velocityY = verTracker. getYVelocity (mPointerId); recodeInfo (velocityX, velocityY); break; case MotionEvent. ACTION_UP: case MotionEvent. ACTION_CANCEL: if (Null! = MVelocityTracker) {mVelocityTracker. clear (); mVelocityTracker. recycle (); mVelocityTracker = null;} break; default: break;} return super. onTouchEvent (event);} private static final String sFormatStr = "velocityX = % f \ nvelocityY = % f "; /*** record the current speed ** @ param velocityX X axis speed * @ param velocityY Y axis speed */private void recodeInfo (final float velocityX, final float velocityY) {final String info = String. format (sFormatStr, velocityX, velocityY); mInfo. setText (info );}}I am the dividing line of tiantiao
Reference: http://blog.csdn.net/bingxianwu/article/details/7446799
What language is used for Android software development?
What else does Javascript proficient android ahan.
What language is used for Android software development?
What else does Javascript proficient android ahan.