关于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,点击需要查看大图,左右滑动能执行翻页. 自己对手势这一块并不 ...
随机推荐
- Do's and Don'ts for Android development
Do's and Don'ts for Android development, by Futurice developers Use Gradle and its recommended proje ...
- 项目管理模式之如何去除SVN标记
原问地址:http://blog.csdn.net/djcken/article/details/7916986 当项目不需要SVN标志的时候,我们一般怎么办哪??可能很多人设置Window ...
- Unity绘制GUI连连看(尚未完善效果和重置)
OneImage.cs public class OneImage : MonoBehaviour { public int row, col; public Rect rect; public Te ...
- SpringMVC 之文件上传 MultipartResolver
基于前面文章的基础上. 一.准备 需要的jar 二.配置 1. spmvc-servlet.xml <?xml version="1.0" encoding=" ...
- android style 退出动画 解决退出动画无效问题
在AndroidMenifest.xml文件里面的Activity声明中,增加自己的Theme声明,如下: <activity android:name=".MyOrderListSe ...
- noip 2005 等价表达式
/* 开始想的是 维护a的每个指数的系数 然而不好办 然而还有^10^10^10这种数据 特殊值带入吧 多搞几个素数 接下来就是玄学的事了 给a赋值之后 就是简单地表达式求值 虽然思路简单 但是字符串 ...
- 基于脚本的动画的计时控制(“requestAnimationFrame”)(转)
requestAnimationFrame 方法的支持,该方法通过在系统准备好绘制动画帧时调用该帧,从而为创建动画网页提供了一种更平滑更高效的方法.在此 API 之前,使用 setTimeout 和 ...
- PHP与memcache和memcached以及安装使用
老规则,在作者寒冰讲之前我们要来明确memcache与memcached这两个东西到底是什么? 说法一: 两个不同版本的php的memcached的客户端 new memcache是pecl扩展库版本 ...
- ASP.NET 页面间数据传递的方法
在做WEB开发时,很多地方会涉及到页面间的数据传递.这几天在完善教务基础系统,遇到了这个问题,上网查了一些资料,现总结如下: 说到页面间数据传递,很多人都会想到通过像Session这样的全局变量,但是 ...
- iOS UI_APPEARANCE_SELECTOR
iOS后属性带UI_APPEARANCE_SELECTOR 可以统一设置全局作用 例如: 1>开关控件 @property(nullable, nonatomic, strong) UIColo ...