VelocityTracker 使用
来源:互联网 发布:算法分析与设计 pdf 编辑:程序博客网 时间:2024/05/09 16:46
第一步的话,当然是得到该类的一个实例 mVelocityTracker = VelocityTracker.obtain();
第二步,需要告诉mVelocityTracker 这个对象你要对那个MotionEvent 进行监控(也就是说得到在那个MotionEvent
上的速度) 对于MotionEvent 的解释文档是这么说的 {对象,用于报告运动(鼠标,笔,手指,轨迹球)事件。这个类可能持有绝对或相对运动}使用
mVelocityTracker.addMovement(ev); 方法来制定一个MotionEvent。
第三步, 这一步就相当简单了直接用 mVelocityTracker.getXVelocity(); 方法获取在水平方向上滑动的速度 用 mVelocityTracker.getYVelocity(); 方法就可以获取垂直方向上滑动的速度了。
最后的话我附上一个完整的例子让大家看的更明白点吧!
VelocityTracker mVelocityTracker = VelocityTracker.obtain();
mVelocityTracker.addMovement(ev);
if (ev.getAction() == MotionEvent.ACTION_UP) {
mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
final int velocityX = (int) mVelocityTracker.getXVelocity();
final int velocityY = (int) mVelocityTracker.getYVelocity();
if (mListener != null) {
int Direction = FLING_NONE;
if (velocityX > SNAP_VELOCITY) {
Direction = FLING_LEFT;
} else if (velocityX < -SNAP_VELOCITY) {
Direction = FLING_RIGHT;
} else if (velocityY > SNAP_VELOCITY) {
Direction = FLING_DOWN;
} else if (velocityY < -SNAP_VELOCITY) {
Direction = FLING_UP;
}
}
- VelocityTracker 使用
- VelocityTracker 使用
- VelocityTracker 使用
- VelocityTracker 使用
- VelocityTracker 使用
- VelocityTracker 使用
- VelocityTracker使用
- Android VelocityTracker的使用
- Android VelocityTracker使用总结
- VelocityTracker使用详解
- Android VelocityTracker的使用
- VelocityTracker的简单使用
- VelocityTracker
- VelocityTracker
- VelocityTracker
- VelocityTracker
- VelocityTracker
- VelocityTracker
- QMessageBox 用法详解
- VC++ CreateProcess
- 开关组件(Switch)
- dxDBGrid使用集锦
- Linux串口编程
- VelocityTracker 使用
- C# 操作数据库(1)
- C#中ref和out
- 解决img的src在firefox,IE7-8下,无法动态加载的问题
- flex传递参数的方式
- 机房收费系统总结之登录功能实例解析抽象工厂+配置文件
- 线程中不执行delegate方法的原因
- HTML代码大全
- android Alertdialog 自定义