Android小总结:VelocityTracker

VelocityTracker是一个什么东西呢,查看VelocityTracker源代码发现有如下注释:

 /**
     * Helper for tracking the velocity of touch events, for implementing
     * flinging and other such gestures.
     *
     * Use {@link #obtain} to retrieve a new instance of the class when you are going
     * to begin tracking.  Put the motion events you receive into it with
     * {@link #addMovement(android.view.MotionEvent)}.  When you want to determine the velocity call
     * {@link #computeCurrentVelocity(int)} and then call {@link #getXVelocity(int)}
     * and {@link #getYVelocity(int)} to retrieve the velocity for each pointer id.
     *
     * 追踪触摸事件速率,实现flinging和其他手势的帮助类
     *
     * 1、当开始追踪的时候,使用obtain来获取VelocityTracker类的实例
     * 2、把接收到的MotionEvent放入到addMovement(android.view.MotionEvent)中
     * 3、当要确定速度时调用computeCurrentVelocity(int),
     *   使用getXVelocity(int)和getYVelocity(int)来检测每个触摸点id的速率
     */

VelocityTracker是一个帮助追踪触摸事件速率的追踪器,可以追踪fliinging和其他触摸手势。

如何使用VelocityTracker呢,注释中提到如下步骤:

     1、当开始追踪的时候,使用obtain来获取VelocityTracker类的实例
     2、把接受到的MotionEvent放入到addMovement(android.view.MotionEvent)中
     3、当要确定速度时调用computeCurrentVelocity(int),
           使用getXVelocity(int)和getYVelocity(int)来检测每个触摸点id的速率

既然VelocityTracker是追踪触摸事件的速度追踪器,当然需要与触摸事件结合使用。

第一步:当你想要追踪触摸事件的速度时,使用private VelocityTracker mVelocityTracker = VelocityTracker.obtain();来获取一个实例,

obtain()方法的源代码:

   /**
     * Retrieve a new VelocityTracker object to watch the velocity of 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值