关于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. C# 实现文件或目录复制到指定目录

    public void CopyFilesToDirKeepSrcDirName(string srcPath, string destDir) { if (Directory.Exists(srcP ...

  2. Java IO - BufferedReader & BufferedWriter

    java.io 包提供丰富的 IO 读写功能,封装在不同的类里面.其中,使用 BufferedReader 和 BufferedWriter 可以方便地进行读.写文件的操作. 使用例子如下: impo ...

  3. L - Kakuro Extension - HDU 3338 - (最大流)

    题意:有一个填数字的游戏,需要你为白色的块内填一些值,不过不能随意填的,是有一些规则的(废话),在空白的上方和作方给出一些值,如果左下角有值说明下面列的和等于这个值,右上角的值等于这行后面的数的和,如 ...

  4. java的异常处理简介

    异常概述 任何一种程序设计语言设计的程序在运行时都有可能出现错误,例如除数为0,数组下标越界,要读写的文件不存在等等. 捕获错误最理想的是在编译期间,但有的错误只有在运行时才会发生. 对于这些错误,一 ...

  5. top -Hp pid 显示所有的线程

    可以显示所有的线程 top -Hp pid [root@jiangyi01.sqa.zmf /home/ahao.mah] #top -Hp 41330 top - 22:49:40 up 27 da ...

  6. OpenStack Networking

    今天的数据中心网络比以往不论什么时候包括的设备都要多,比如server.网络设备.存储系统和安全设备等.这当中有非常多被近一步划分为多个虚拟机和虚拟网络.IP地址的数量.路由配置和安全规则能够迅速达到 ...

  7. 10 Powerful Apache Modules--reference

    Apache is the most popular web server in the world,because it is more efficient than others.Thrust o ...

  8. yii 自动生成的内容,分页信息(Displaying 1-10 of 15 results.)如何修改或是yii cgridview template summary

    问的白一点就是 Displaying 1-10 of 15 results 如何翻译 如果搜索的话, 搜这个会出来很多内容 yii cgridview template summary 好了,其他不说 ...

  9. linux 声音大小调整的命令

    alsamixer 输入上面的命令 回车即可看到图形界面,界面如下 ┌──────────────────────────── AlsaMixer v1.0.27.1 ──────────────── ...

  10. python复制--笔记

    对象引用: >>> songs = ["Bee","Core","Love"] >>> bat = so ...