关于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,点击需要查看大图,左右滑动能执行翻页. 自己对手势这一块并不 ...
随机推荐
- Javascript 操作select控件大全(新增、修改、删除、选中、清空、判断存在等)
1判断select选项中 是否存在Value="paraValue"的Item 2向select选项中 加入一个Item 3从select选项中 删除一个Item 4删除selec ...
- 使用read(),write(),seekg(),seekp()实现二进制方式文件随机存取
// binary.cpp -- binary file I/O #include <iostream> #include <fstream> #include <iom ...
- Java学习日记-2 零零碎碎
一.使用Scanner类进行控制台的输入 文档中Scanner类的定义为A simple text scanner which can parse primitive types and string ...
- remastersys
- Runtime.getRuntime().addShutdownHook(shutdownHook);
今天在阅读Tomcat源码的时候,catalina这个类中使用了下边的代码,不是很了解,所以google了一下,然后测试下方法,Tomcat中的相关代码如下: Runtime.getRuntime() ...
- 启动android默认浏览器
一.启动android默认浏览器 Intent intent = new Intent(); intent.setAction("android.intent.action. ...
- Atitit.Gui控件and面板----数据库区-mssql 2008 权限 配置 报表查看成员
Atitit.Gui控件and面板----数据库区-mssql 2008 权限 配置 报表查看成员 1. 配置server连接权限 1 2. 配置数据库权限 1 3. 设置表格/视图安全性 2 1. ...
- 初次使用cocoapods注意事项
在仅仅用cocoapods时可能会遇到各种各样的错误和问题 这里中总结下: 1.首先使用cocoapods有非常多优点,在github上非常多优秀的开源项目都用到了它;假设你不会使用它,那么非常多优秀 ...
- C# SqlHelper
操作数据库时,经常会把常用的方法封装到一个类中,这里简单写了一个SQLHelper类,供我平时调用. public static class SqlHelper { private static re ...
- 小学生之使用Mybatis反向生成dao,entity,xml
本小学生刚进公司的时候,就一顿装逼,不管别人问我啥我都会说:"会"!毕竟在公司吗,什么都要装,不要别人看出你的底细.不过有一天,听说用Mybatis可以反向生成dao(第一次听说) ...