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=

随便看看

powerdesigner与数据库之间的连接

useUnicode=true&characterEncoding=UT8&serverTimezone=UTC 9JDBCdriverjarfiles:指定连接的jar包路径。测试连接。连接成功。进入工作区。3.2 3.2powerdesigner连接到oracle。其原理与连接MySQL的原理相同。在已安装的oracle下找到ojdbc1...

解决cookie跨域访问

如果用户在登录(记录用户上下文信息)后在浏览器客户端上写入cookie,则只能访问与创建cookie的页面相同目录或创建cookie页面的子目录中的网页。这是因为cookie可以由其路径下的页面访问。然后,如果您想在域a中生成一个可以被域a和域B访问的cookie,则需要将cookie的域设置为.test.com;...

websphere application server (was) 安装8.5.5.18

目录环境准备所需的软件或系统版本安装包目录结构安装步骤安装was8.5.0.0升级到8.5.5.18打开浏览器以访问控制台环境准备如果系统主机名不是localhost,您需要将所需的软件或系统版本jdk1.8centos7.5WAS提前添加到/etc/hosts/文件中_ ND_V8.5_1_OF_3.zipWAS_ ND_V3.5_2_OF_3.zip代理...

ArcGIS Server服务状态正在停止。。。问题BUG解决

1、 ArcGISServer服务器存在服务问题:ArcGISServerManager的所有服务都显示为“正在停止…”。N个解决方案1)港口占用问题。端口4000-4002已被其他程序占用,导致服务无法正常启动。您可以通过CMD找到相关PID占用的端口,停止它,然后启动GIS服务。您也可以在安装目录中将其手动更改为D:ProgramFiles ArcGIS...

Selenium操作示例——鼠标悬停显示二级菜单,再点击二级菜单或下拉列表

这两天在python中玩selenium时,我遇到了一个问题,那就是鼠标移动到页面上的一个按钮或菜单,二级菜单或下拉菜单自动弹出,然后二级菜单或者下拉列表自动点击。...

开源BI分析工具Metabase配置与完全使用手册

文章目录简介安装初始配置数据分析简单查询创建场景创建集合和仪表盘自定义查询原生查询sql变量动态sql片段管理员操作添加数据库连接oracle成员管理邀请新成员权限配置数据权限文件夹权限邮箱配置定时任务简介Metabase是一个免费的BI分析工具,可以帮助你把数据库中的数据更好的呈现给更多人,通过建立一个”查询“来提炼数据,再以图形化的方式做展示。上手简单,...