关于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值,计算结果带正负号。

不知道这理解正不正确,如有错误望指正。
关于GestureDetector.OnGestureListener的onScroll参数distance问题的更多相关文章
- GestureDetector.OnGestureListener
为了加强鼠标响应事件,Android提供了GestureDetector手势识别类.通过GestureDetector.OnGestureListener来获取当前被触发的操作手势(Single Ta ...
- android学习——GestureDetector.OnGestureListener 详解
Android Touch Screen 与传统Click Touch Screen不同,会有一些手势(Gesture),例如Fling,Scroll等等.这些Gesture会使用户体验大大提升.An ...
- 手势GestureDetector.OnGestureListener事件的调起
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionE ...
- 说说GestureDetector.OnGestureListener onScroll函数
public abstract boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) ...
- 手势识别官方教程(4)在挑划或拖动手势后view的滚动用ScrollView和 HorizontalScrollView,自定义用Scroller或OverScroller
简单滚动用ScrollView和 HorizontalScrollView就够.自定义view时可能要自定义滚动效果,可以使用 Scroller或 OverScroller Animating a S ...
- android GestureDetector 手势基础
1. 当用户触摸屏幕的时候,会产生许多手势,例如down,up,scroll,filing等等,我们知道View类有个View.OnTouchListener内部接口,通过重写他的onTouch(Vi ...
- 【Andorid------手势识别】GestureDetector和SimpleOnGestureListener的使用教程(转)——
FROM:http://www.cnblogs.com/transmuse/archive/2010/12/02/1894833.html 1. 当用户触摸屏幕的时候,会产生许多手势,例如down,u ...
- OnTouchListener事件监听实现方式之GestureDetector
当用户触摸屏幕的时候,会产生许多手势,例如down,up,scroll,filing等等. 一般情况下,我们知道View类有个View.OnTouchListener内部接口,通过重写他的onTouc ...
- GestureDetector类及其用法
转载子:http://www.cnblogs.com/rayray/p/3422734.html 项目中有需求:针对一个imageview,点击需要查看大图,左右滑动能执行翻页. 自己对手势这一块并不 ...
随机推荐
- 9. memcpy() memccpy() memmove() strcpy() memset()
部分参考: http://www.cppblog.com/kang/archive/2009/04/05/78984.html 表头文件: #include <string.h>定义函数: ...
- Exception starting filter struts2 java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
按教程,使用Convention插件进行配置 教程中说只要加入struts2-convention-plugin-2.3.4.1.jar这个jar包就可以使用. 按照这种方法部署后,启动tomcat报 ...
- [转载]使用uiautomator做UI测试
这个只是单纯的mark一下.还没有认真去研究.鉴于最近也不会做手机的自动化测试,所以留作以后参考吧. 转自: http://blog.chengyunfeng.com/?p=504 在Android ...
- iOS音频处理
ios音频处理 1. iOS底层音频处理技术(带源代码) http://www.cocoachina.com/ios/20111122/3563.html 2.ios 音频入门 http://blog ...
- SqlServer中计算列详解
计算列区别于需要我们手动或者程序给予赋值的列,它的值来源于该表中其它列的计算值.比如,一个表中包含有数量列Number与单价列Price,我们就可以创建计算列金额Amount来表示数量*单价的结果值, ...
- 通过linux ssh远程登录另一台Linux,无需密码,用证书验证
1.首先登入一台linux服务器,此台做为母机(即登入其他linux系统用这台做为入口):执行一行命令生成key文件:ssh-keygen -t rsa 2.在母机上,进入/roo/.ssh目录,找到 ...
- 关于“无法解析的外部符号”和“该符号在函数_wmain 中被引用”的问题
在VS2008和opendv的环境下: error LNK2019: 无法解析的外部符号_cvDestroyWindow,该符号在函数_wmain 中被引用 error LNK2019: 无法解析的外 ...
- Java基础知识强化86:BigInteger类之BigInteger概述和构造方法
1. BigInteger类概述 可以让超过Integer范围内的数据进行运算 2. 构造方法: public BigInteger(String val) 3. 代码示例: package cn ...
- python集合set,frozenset--笔记
<Python3程序开发指南>笔记. python提供了2种内置的集合类型:可变的set类型.固定的frozenset类型. 只有可哈希运算的对象可添加到集合中.可哈希的数据类型:floa ...
- cogs 线型网络(状压dp)
/* 需要好大的空间..... 而且lowbit理解的不是很好 先放到博客里 以后慢慢研究 */ #include<iostream> #include<cstdio> #in ...