使用VelocityTracker来完成MotionEvent移动速率计算

先看效果图

关键代码(此处记录单点):

switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
if (veloctiy==null) {
veloctiy=VelocityTracker.obtain();
}
veloctiy.addMovement(event);
break;
case MotionEvent.ACTION_MOVE:
veloctiy.addMovement(event);
veloctiy.computeCurrentVelocity(1000);
Log.i("lzh", veloctiy.getXVelocity()+"y:"+veloctiy.getYVelocity());

case MotionEvent.ACTION_UP:
veloctiy.clear();
break;
}

多点传递触点id,即可。

原文地址:https://www.cnblogs.com/lzh-Linux/p/5046613.html