关于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问题的更多相关文章

  1. GestureDetector.OnGestureListener

    为了加强鼠标响应事件,Android提供了GestureDetector手势识别类.通过GestureDetector.OnGestureListener来获取当前被触发的操作手势(Single Ta ...

  2. android学习——GestureDetector.OnGestureListener 详解

    Android Touch Screen 与传统Click Touch Screen不同,会有一些手势(Gesture),例如Fling,Scroll等等.这些Gesture会使用户体验大大提升.An ...

  3. 手势GestureDetector.OnGestureListener事件的调起

    @Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionE ...

  4. 说说GestureDetector.OnGestureListener onScroll函数

    public abstract boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) ...

  5. 手势识别官方教程(4)在挑划或拖动手势后view的滚动用ScrollView和 HorizontalScrollView,自定义用Scroller或OverScroller

    简单滚动用ScrollView和 HorizontalScrollView就够.自定义view时可能要自定义滚动效果,可以使用 Scroller或 OverScroller Animating a S ...

  6. android GestureDetector 手势基础

    1. 当用户触摸屏幕的时候,会产生许多手势,例如down,up,scroll,filing等等,我们知道View类有个View.OnTouchListener内部接口,通过重写他的onTouch(Vi ...

  7. 【Andorid------手势识别】GestureDetector和SimpleOnGestureListener的使用教程(转)——

    FROM:http://www.cnblogs.com/transmuse/archive/2010/12/02/1894833.html 1. 当用户触摸屏幕的时候,会产生许多手势,例如down,u ...

  8. OnTouchListener事件监听实现方式之GestureDetector

    当用户触摸屏幕的时候,会产生许多手势,例如down,up,scroll,filing等等. 一般情况下,我们知道View类有个View.OnTouchListener内部接口,通过重写他的onTouc ...

  9. GestureDetector类及其用法

    转载子:http://www.cnblogs.com/rayray/p/3422734.html 项目中有需求:针对一个imageview,点击需要查看大图,左右滑动能执行翻页. 自己对手势这一块并不 ...

随机推荐

  1. 【搬运】一分钟快速入门OpenStack

      一.它是什么,能干什么   想认识一个事物,必须先弄明白它是什么,能干什么.   首先说一下,openstack是一个搭建云平台的一个解决方案,说他不是个软件,但是我觉得说是一个软件,能够让初学者 ...

  2. 大暴力——[HAOI]2012音量调节

    题目:[HAOI]2012音量调节 描述: 问题描述 一个吉他手准备参加一场演出.他不喜欢在演出时始终使用同一个音量,所以他决定每一首歌之前他都要改变一次音量.在演出开始之前,他已经做好了一个列表,里 ...

  3. iOS内存管理(一)

    最近有时间,正好把iOS相关的基础知识好好的梳理了一下,记录一下内存相关方面的知识. 在理解内存管理之前我觉得先对堆区和栈区有一定的了解是非常有必要的. 栈区:就是由编译器自动管理内存分配,释放过程的 ...

  4. IBinder对象在进程间传递的形式(一)

    命题 当service经常被远程调用时,我们经常常使用到aidl来定一个接口供service和client来使用,这个事实上就是使用Binder机制的IPC通信.当client bind servic ...

  5. mongodb的write concern

    mongodb有一个write concern的设置,作用是保障write operation的可靠性.一般是在client driver里设置的,和db.getLastError()方法关系很大 一 ...

  6. JAVA-1-学习历程1:基础知识1

     前言:此文属于个人学习中总结记录的较重要的知识点,分享一下.望对刚開始学习的人有点用. 视频04   语句.函数.数组 1.函数的重载 2.数组内存空间的划分 栈.堆 视频05    数组 1. ...

  7. QTimerLine类学习

      QTimeLine类提供了控制动画的时间轴. 类型:enum CurveShape{EaseInCurve,EaseOutCurve,EaseInOutCurve,LinearCurve,Sine ...

  8. 大数据笔记03:大数据之Hadoop的安装

    1.安装Hadoop (1)准备Linux环境 (2)安装JDK (3)配置Hadoop 2.准备Linux环境 (1)我们用户可能都是使用Windows环境,一般用户都是先安装虚拟机,然后在虚拟机上 ...

  9. 几个常用的ps命令

    1. ps aux If you are looking for a short summary of the active processes, use  ps aux [root@rhel7 tm ...

  10. Visual Studio2015 Community一些必备插件

    Visual Studio2015 Community一些必备插件 是不是感觉虽然VS2015的代码编辑能力已经很强大了,但是总感觉差了那么一些呢?不用担心,它有很多非常强大的插件,能够让你打代码事半 ...