帮助器用于跟踪触摸事件的速度,用于实现投掷和其他此类手势。用于obtain()
在开始跟踪时检索类的新实例。将收到的动作事件放入其中 addMovement(MotionEvent)
。当你想确定速度调用 computeCurrentVelocity(int)
然后调用getXVelocity(int)
并getYVelocity(int)
检索每个指针id的速度。
公共方法
void | addMovement(MotionEvent event) 为 VelocityTracker 传入触摸事件(包括 |
void | clear() 重置 VelocityTracker 回其初始状态。 |
void | computeCurrentVelocity(int units) 根据已经传入的触摸事件计算出当前的速度,可以通过 注:一般在 case MotionEvent.ACTION_MOVE: mVelocity.computeCurrentVelocity(VELOCITY_DURATION); 参数 单位您希望速度输入的单位。值为1表示每毫秒像素数,1000表示每秒像素数等。maxVelocity可以通过此方法计算的最大速度。必须在与units参数相同的单位中声明此值。该值必须为正数。 |
float | 获取最后计算的水平方向速度,使用此方法前需要记得先调用 |
float | getXVelocity(int id) 获取对应的手指id最后计算的水平方向速度,使用此方法前需要记得先调用 |
float | getYVelocity(int id) 获取对应的手指id最后计算的垂直方向速度,使用此方法前需要记得先调用 |
float | 获取最后计算的垂直方向速度,使用此方法前需要记得先调用 |
static VelocityTracker | obtain() 获取一个 VelocityTracker 对象。VelocityTracker的构造函数是私有的,也就是不能通过new来创立 |
void | recycle() 回收 VelocityTracker 实例。 |