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=

随便看看

NodeJs使用jwt生成token以及使用express-jwt校验和解密token

=0){//当数据库有当前用户时,它返回tokenlettoken=jwt.sign;res.send}else{res.send}}catch{//p抛出异常并将其发送到错误中间件以处理console.log;next;}})//注册接口路由器。post('/register',异步(req,res,next)=˃{let{用户名,密码,昵称}=req-b...

H3C 12508 收集诊断信息

案例:H3C12508单板卡出现remove状态,需要配合研发收集诊断信息。)总体:12500交换机返回三种文件----故障时诊断信息,主备单板的日志文件,主备单板的诊断日志操作步骤:一、故障时诊断信息:disdiagnostic-informationdiag收集必须在问题出现的时候,单板重起之前执行。在save时请选择Y保存到CF卡方式。一般情况下,此命...

2.页面绘制和引入组件库uView

文本+背景色的形式,而不是横幅图的形式,可以节省未来的工作量。在index.vue中,关于开关的代码:EFGHIJKLMNOPQRSTUWXYZB˃DEFGHIJKLNNOPQRSTUVWXYZEFGHIJKLMNOPQRSTUVWXYZ导出默认值{data(){return{}},onLoad()},方法:{}}。横幅{width:100%;height:...

css实现切角效果

html<divclass=“corner”>#58a0);#58a0)右,#58a0)左;3.四个倒角css。角{width:4。圆弧倒角css。右上角(width:#58a0);背景重复:无重复;...

uniapp之页面间传递和接收数组

uni-app如何在页面之前发送和传递数组?如果阵列是直接发送和传递的,则收到的消息如下所示。无法获取更多的对象值。接收数组对象的参数。您可以首先将数组转换为JSON字符串,然后在将其传递到页面后将其解析为JavaScript对象。...

一分钟制作U盘版BT3

一分钟生产BT3U磁盘版本方便、快捷、简单、无效且不可退款。BT3磁盘版本,大约694MB,可以直接烧录,然后用CD引导进入BT3。连接如下:http://ftp.heanet.ie/mirrors/backtrack/bt3-final.isoU磁盘版本Bt3,约783MB,连接为:http://cesium.di.uminho.pt/pub/backtr...