VelocityTracker计算速率
来源:互联网 发布:autodesk软件卸载工具 编辑:程序博客网 时间:2024/06/05 16:09
android.view.VelocityTracker主要用跟踪触摸屏事件(flinging事件和其他gestures手势事件)的速率。用addMovement(MotionEvent)函数将Motion event加入到VelocityTracker类实例中.你可以使用getXVelocity() 或getXVelocity()获得横向和竖向的速率到速率时,但是使用它们之前请先调用computeCurrentVelocity(int)来初始化速率的单位 。
主要函数
Add a user's movement to the tracker.
Reset the velocity tracker back to its initial state.
Compute the current velocity based on the points that have been collected.
int unitis表示速率的基本时间单位。unitis值为1的表示是,一毫秒时间单位内运动了多少个像素, unitis值为1000表示一秒(1000毫秒)时间单位内运动了多少个像素
floatVelocity表示速率的最大值
Equivalent to invoking
computeCurrentVelocity(int, float)
with a maximum velocity of Float.MAX_VALUE.Retrieve the last computed X velocity.
Retrieve the last computed X velocity.
Retrieve the last computed Y velocity.
Retrieve the last computed Y velocity.
Retrieve a new VelocityTracker object to watch the velocity of a motion.
Return a VelocityTracker object back to be re-used by others.
示例:
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 ()函数来获得当前的速度
0 0
- VelocityTracker计算速率
- 天天记录 - 使用VelocityTracker计算滑动速率
- android VelocityTracker跟踪触摸屏事件的速率
- 网络传输速率计算
- 计算帧速率
- 宽带速率计算
- 速率的计算
- qam调制速率计算
- 802.11速率计算
- MCS速率计算公式
- 网络带宽、速率计算
- VelocityTracker
- VelocityTracker
- VelocityTracker
- VelocityTracker
- VelocityTracker
- VelocityTracker
- velocitytracker
- linux 如何以树形结构显示文件目录结构
- JavaLogin小框架制作【精品博客】
- RxJava
- 路漫漫其修远兮
- AOP 之 6.4 基于@AspectJ的AOP ——跟我学spring3
- VelocityTracker计算速率
- 运维之下 笔记 三(运维平台)
- LPC1778/1788的初步开发问题
- 746 D. Green and Black Tea codeforces
- CAD的一些命令,希望对大家有帮助哦!!!
- 如何查看知道某一个网站是由哪种编程语言写的?绝对准确全面!(精)
- sql server分页查询
- 短信验证模板
- androidstudio导入so简单的方法