VelocityTracker简介

摘要:
android.view。VelocityTracker主要跟踪触摸屏事件(闪烁事件和其他手势)的发生率。使用addMovement(MotionEvent)函数将MotionEvent添加到VelocityTracker类实例中。您可以使用getXVelocity()或getXVelicity()将水平和垂直速度设置为速度,但请在使用它们之前调用computeC
android.view.VelocityTracker主要用跟踪触摸屏事件(flinging事件和其他gestures手势事件)的速率。用addMovement(MotionEvent)函数将Motion event加入到VelocityTracker类实例中.你可以使用getXVelocity()getXVelocity()获得横向和竖向的速率到速率时,但是使用它们之前请先调用computeCurrentVelocity(int)来初始化速率的单位 。
主要函数
Public Methods
voidaddMovement(MotionEventevent)
Add a user's movement to the tracker.
voidclear()
Reset the velocity tracker back to its initial state.
voidcomputeCurrentVelocity(int units, float maxVelocity)
Compute the current velocity based on the points that have been collected.
intunitis表示速率的基本时间单位。unitis值为1的表示是,一毫秒时间单位内运动了多少个像素, unitis值为1000表示一秒(1000毫秒)时间单位内运动了多少个像素
floatVelocity表示速率的最大值
voidcomputeCurrentVelocity(int units)
Equivalent to invokingcomputeCurrentVelocity(int, float)with a maximum velocity of Float.MAX_VALUE.
abstract TgetNextPoolable()
floatgetXVelocity()
Retrieve the last computed X velocity.
floatgetXVelocity(int id)
Retrieve the last computed X velocity.
floatgetYVelocity(int id)
Retrieve the last computed Y velocity.
floatgetYVelocity()
Retrieve the last computed Y velocity.
abstract booleanisPooled()
staticVelocityTrackerobtain()
Retrieve a new VelocityTracker object to watch the velocity of a motion.
voidrecycle()
Return a VelocityTracker object back to be re-used by others.
abstract voidsetNextPoolable(T element)
abstract voidsetPooled(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简介》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇wtl学习总结idou老师教你学istio 21:基于角色的访问控制下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

SqlLite 简明教程

LIMIT运算符LIMIT子句指定要返回的记录数。WHERE表达式LIMITnumberLIKE运算符LIKE操作符用于在WHERE子句的列中搜索指定的模式。SELECT可以是简单的,也可以是复合的。请注意,UNION中的SELECT语句必须具有相同数量的字段。NOT NULL约束强制字段始终包含值。SQLNULL约束NULL值缺少未知数据。SQLPRIMA...

es6 解构赋值

functiondemo(){return{"name":"张三","age":21}}var{name,age}=demo();console.log;//结果:张三console.log;//结果:21三、定义函数参数functiondemo{console.log;console.log;console.log;}demo;四、函数参数的默认值传统的参...

java报表实现excel一样冻结表头的功能

增加了几个新的指标,后台sql改了,拿过来只须在一个dao类中修改就足够了,可恨的是客户又提出来改报表表样,加个类似excel冻结表头的功能。...

Android 帧动画使用

本文介绍使用AnimationDrawable类来实现动画效果。oneshot="false",表示让动画一直循环播放下去。.backgroundasAnimationDrawableani.start()当动画正在播放时,调用start()方法是不会影响当前播放的。˃android:oneshot="true",动画播放1次后就会自行停止并保持在最后一帧。...

ES基本查询总结

ES与数据库比较查询操作Elasticsearch中当我们设置Mapping完毕后,就可以按照设定的方式导入数据。以下内容的原文需要参考ES官方文档1、结构化检索针对字段类型:日期、时间、数字类型,以及精确的文本匹配。结构化检索特点:*1)结构化查询,我们得到的结果总是非是即否,要么存于集合之中,要么存在集合之外。term查询是简单的,它接受一个字段名以及我...

TensorRT在ubuntu18.04的安装

安装TensorRT前需要安装Cuda和cudnn,安装步骤可以参考ubuntu安装cuda和cudnn。...