參照自: http://blog.jrj.com.cn/4586793646,5298605a.html



android.view.VelocityTracker主要用跟踪触摸屏事件(flinging事件和其它gestures手势事件)的速率。用addMovement(MotionEvent)函数将Motion event增加到VelocityTracker类实例中.你能够使用getXVelocity() 或getXVelocity()获得横向和竖向的速率到速率时,可是使用它们之前请先调用computeCurrentVelocity(int)来初始化速率的单位
主要函数
Public Methods
void addMovement(MotionEvent event)

Add a user's movement to the tracker.
void clear()

Reset the velocity tracker back to its initial state.
void computeCurrentVelocity(int
units, float maxVelocity)

Compute the current velocity based on the points that have been collected.
的表示是,一毫秒时间单位内运动了多少个像素, unitis值为表示一秒(1000毫秒)时间单位内运动了多少个像素
floatVelocity表示速率的最大值
void computeCurrentVelocity(int units)

Equivalent to invoking computeCurrentVelocity(int,
float)
 with a maximum velocity of Float.MAX_VALUE.
abstract T getNextPoolable()
float getXVelocity()

Retrieve the last computed X velocity.
float getXVelocity(int id)

Retrieve the last computed X velocity.
float getYVelocity(int id)

Retrieve the last computed Y velocity.
float getYVelocity()

Retrieve the last computed Y velocity.
abstract boolean isPooled()
static VelocityTracker obtain()

Retrieve a new VelocityTracker object to watch the velocity of a motion.
void recycle()

Return a VelocityTracker object back to be re-used by others.
abstract void setNextPoolable(T element)
abstract void setPooled(boolean isPooled)
演示样例: 
    private VelocityTracker mVelocityTracker;//生命变量 
    //在onTouchEvent(MotionEvent ev)中 
    if (mVelocityTracker == null) { 
            mVelocityTracker = VelocityTracker.obtain();//获得VelocityTracker类实例 
    } 
    mVelocityTracker.addMovement(ev);//将事件增加到VelocityTracker类实例中 
    //推断当ev事件是MotionEvent.ACTION_UP时:计算速率 
    final VelocityTracker velocityTracker = mVelocityTracker; 
    // 1000 provides pixels per second 
    velocityTracker.computeCurrentVelocity(1, (float)0.01); //设置maxVelocity值为0.1时,速率大于0.01时,显示的速率都是0.01,速率小于0.01时,显示正常 
    Log.i("test","velocityTraker"+velocityTracker.getXVelocity());                     
    velocityTracker.computeCurrentVelocity(1000); //设置units的值为1000,意思为一秒时间内运动了多少个像素 
    Log.i("test","velocityTraker"+velocityTracker.getXVelocity()); 
大体的使用是这种:
当你须要跟踪触摸屏事件的速度的时候,使用obtain()方法来获得VelocityTracker类的一个实例对象
在onTouchEvent回调函数中,使用addMovement(MotionEvent)函数将当前的移动事件传递给VelocityTracker对象
使用computeCurrentVelocity  (int units)函数来计算当前的速度,使用 getXVelocity  ()、 getYVelocity
 ()函数来获得当前的速度

VelocityTracker简要的更多相关文章

  1. JavaScript权威设计--JavaScript函数(简要学习笔记十一)

    1.函数调用的四种方式 第三种:构造函数调用 如果构造函数调用在圆括号内包含一组实参列表,先计算这些实参表达式,然后传入函数内.这和函数调用和方法调用是一致的.但如果构造函数没有形参,JavaScri ...

  2. JavaScript权威设计--JavaScript函数(简要学习笔记十)

    1.函数命名规范 函数命名通常以动词为前缀的词组.通常第一个字符小写.当包含多个单词时,一种约定是将单词以下划线分割,就像"like_Zqz()". 还有一种就是"lik ...

  3. [译]Angular2 和TypeScript -- 一次简要的预览

    原文链接:https://www.infoq.com/articles/Angular2-TypeScript-High-Level-Overview 作者:  Yakov Fain Posted o ...

  4. 内网劫持渗透新姿势:MITMf简要指南

    声明:本文具有一定攻击性,仅作为技术交流和安全教学之用,不要用在除了搭建环境之外的环境. 0×01 题记 又是一年十月一,想到小伙伴们都纷纷出门旅游,皆有美酒佳人相伴,想到这里,不禁潸然泪下.子曰:& ...

  5. android VelocityTracker 速度追踪器的使用及创建

    VelocityTracker 速度追踪 第一,创建方式: VelocityTracker  mVelocityTracker  = new VelocityTracker .obtain() 第二, ...

  6. markdown简要说明显示样式

    markdown 什么是markdown:     Markdown是一种可以使用普通文本编辑器编写的标记语言,通过简单的标记语法,它可以使普通文本内容具有一定的格式.   Markdown具有一系列 ...

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

    先看效果图 关键代码(此处记录单点): switch (event.getAction()){ case MotionEvent.ACTION_DOWN: if (veloctiy==null) { ...

  8. 简要介绍BASE64、MD5、SHA、HMAC几种方法。

    加密解密,曾经是我一个毕业设计的重要组件.在工作了多年以后回想当时那个加密.解密算法,实在是太单纯了.     言归正传,这里我们主要描述Java已经实现的一些加密解密算法,最后介绍数字证书.     ...

  9. Java Reference简要概述

    @(Java)[Reference] Java Reference简要概述 Reference对象封装了其它对象的引用,可以和普通的对象一样操作. Java提供了四种不同类型的引用,引用级别从高到低分 ...

随机推荐

  1. 解决java中ZipFile解压缩时候的中文路径和乱码问题

    JAVA中对jar文件或zip文件解压的时候,能够使用JDK内置的API:JarFile和ZipFile,在windows下解压这2种格式文件的时候,常常报下面错误: Exception in thr ...

  2. Python 线程启动的四种方式

    import threading,_thread def action(i): print(i **32) #带有状态的子类 class Mythread(threading.Thread): def ...

  3. iOS开发Quzrtz2D:十一:图片截屏以及图片擦除

    一:图片截屏:截取的是控制器的view #import "ViewController.h" @interface ViewController () @end @implemen ...

  4. php生成唯一字符串

    $units = array(); //循环生成好多个唯一字符串 for($i=0;$i<1000000;$i++){ $units[]=md5(uniqid(md5(microtime(tru ...

  5. Django之settings.py 的media路径设置

    在一个 models 中使用 FileField 或 ImageField 需要以下步骤: 1. 在你的 settings.py文件中, 定义一个完整路径给MEDIA_ROOT 以便让 Django在 ...

  6. Android 报错 Error:(303, 27) 错误: 找不到符号 符号: 方法 sin(float) 位置: 类 FloatMath

    今天更新了sdk,升级到Android SDK 23.发现Android studio用23编译 SlidingMenu时出错,错误如下: 报错的地方这这里: float distanceInflue ...

  7. Android的NDK开发(1)————Android JNI简介与调用流程

    1.JNI简介 JNI全称为Java Native Interface(Java本地调用).从Java1.1开始,JNI成为java平台的一部分,它允许Java代码和其他语言写的代码(如C&C ...

  8. MySQL中关于OR条件的优化

    转载 MySQL在 5.0版本中引入新特性:索引合并优化(Index merge optimization),当查询中单张表可以使用多个索引时,同时扫描多个索引并将扫描结果进行合并. 该特新主要应用于 ...

  9. Python实战:如何隐藏自己的爬虫身份

    使用爬虫访问网站,需要尽可能的隐藏自己的身份,以防被服务器屏蔽,在工作工程中,我们有2种方式来实现这一目的,分别是延时访问和动态代理,接下来我们会对这两种方式进行讲解 1.延时访问 见名之意,延时访问 ...

  10. hello.c内核模块编译 -- linux内核

    Linux开发模块,在本机上看调试信息的方法走通了.当前版本号2.6.32-32-generic uname –r 能够查询 这里取module_param()作为样例. 该宏被定义在include/ ...