关于GestureDetector.OnGestureListener类的onScroll方法参数distanceX和distanceY问题
2013-08-26 15:09
435 查看
关于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 theinitial on down MotionEvent and
the current move MotionEvent.
The distance in x and y is alsosupplied 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. |
true if the eventis consumed, else false
“The distance along the X axis that has been scrolledsince 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值,计算结果带正负号。
不知道这理解正不正确,如有错误望指正。
相关文章推荐
- 关于GestureDetector.OnGestureListener的onScroll参数distance问题
- 关于a标签中js函数function(va1,va2)方法传递中文参数报错不执行的问题解答
- 安卓模拟器上关于ListView设置了OnScrollListener之后onScrollStateChanged()和onScroll方法监听不到的问题
- 【转】【第三方包】【Android Universal Imageloader】关于displayImage方法中URI参数的问题
- 关于replace()方法中第二个参数的转义问题
- 关于laravel5.5控制器方法参数依赖注入原理深度解析及问题修复
- 关于jQuery方法解析(一)append-参数设置问题
- 关于DataTable的Select方法参数表达式区分大小写的问题
- android -- 小问题 关于ListView设置了OnScrollListener之后onScrollStateChanged()和onScroll方法监听不到的问题
- 关于java语言中方法参数传递问题
- 关于ListView设置了OnScrollListener之后onScrollStateChanged()和onScroll方法监听不到的问题
- android -- 小问题 关于ListView设置了OnScrollListener之后onScrollStateChanged()和onScroll方法监听不到的问题
- 关于java代码中的注释问题。(类中方法的注释,我们一般都要写上这个方法的文档(doc),方法的参数也要有它的文档)
- 关于Future.cancel(mayInterruptIfRunning)方法的参数的问题
- 关于上个Flex-Jsp-DB例子中Flex和Jsp传递中文参数问题的解决方法!(Tomcat服务器)
- 关于Selector方法需要多个参数的问题解决方法
- 礼拜三log~常用java函数 & jQuery ajax的serialize() 方法 & 获取参数 & IE浏览器下button显示黑边框问题 & 关于ajax
- 关于Spring MVC同名参数绑定问题的解决方法
- 关于向方法中传递参数的问题
- 关于获取jquery ajax方法返回值参数的问题