关于GestureDetector.OnGestureListener的onScroll参数distance问题
关于GestureDetector.OnGestureListener类的onScroll方法参数distanceX和distanceY问题
看到有文章上说onScroll方法中distanceX和distanceY是指“distanceX,是前后两次call的X距离,不是e2与e1的水平距离; 是前后两次call的Y距离,不是e2与e1的垂直距离”
然后怎么也没理解出来这两个参数是什么意思
于是去实践了一下:
以下是谷歌官方API说明:
public abstract boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
Added in API level 1
Notified when a scroll occurs with the initial on down MotionEvent and the current move MotionEvent. The distance in x and y is also supplied for convenience.
Parameters
e1 |
The first down motion event that started the scrolling. |
e2 |
The move motion event that triggered the current onScroll. |
distanceX |
The distance along the X axis that has been scrolled since the last call to onScroll. This is NOT the distance between e1 and e2. |
distanceY |
The distance along the Y axis that has been scrolled since the last call to onScroll. This is NOT the distance between e1 and e2. |
Returns
true if the event is consumed, else false
“The distance along the X axis that has been scrolled since the last call to onScroll. This is NOT the distance between e1 and e2.”
这句话按我自己翻译出来的意思是“在上一次(最后一次)调用onScroll方法沿着X轴所滑动的距离。不是e1和e2之间的距离”
我的理解是:distanceX是滑动起点和终点的水平距离,而不是起点和终点的直线距离。
写了个例子在LogCat中输出了一下它们的值:
发现
distanceX的值等于e1的X值减去e2的X值,计算结果带正负号。
distanceY的值等于e1的Y值减去e2的Y值,计算结果带正负号。
不知道这理解正不正确,如有错误望指正。
最新文章
- 二叉树[C实现]
- java基础 - 冒泡排序,随机数算法
- win7下硬盘安装ubuntu
- PHP、Java对称加密中的AES加密方法
- linux 下 用户与用户组
- JAVA中使用JSON进行数据传递
- iOS 中@property() 括号中,可以填写的属性?
- 【AngularJs】---$sce 输出Html
- 分享一个option样式传递给select当前选中样式
- 处理date类型对象的方式
- CPU自制入门——笔记
- linux expect, spawn用法小记
- Java Socket与操作系统的关系
- MVC轻量web应用
- Angular 学习笔记 ( 链接服务器 )
- ng-book札记——路由
- 如何将新建的项目完整的提交到gitlab上?
- Maven依赖中的scope详解
- Effective C++ 条款46
- Python之入门篇1