用于追踪手指滑动过程中的速度。
在View的ontouchEvent方法中追踪当前单击事件的速度。
VelocityTracker velocityTracker=VelocityTracker.obtain();
velocityTracker.addMovement(event);
获得当前速度
velocityTracker.computeCurrentVelocity(1000);
int xVelocity=(int)velocityTracker.getXVelocity();
int yVelocity=(int)velocityTracker.getYVelocity();
computeCurrentVelocity这个方法的参数表示的是一个时间间隔,它的而单位是ms。
回收资源
velocityTracker.clear();
velocityTracker.recycle();