关于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. 多线程爬虫Java调用wget下载文件,独立线程读取输出缓冲区

    写了个抓取appstore的,要抓取大量的app,本来是用httpclient,但是效果不理想,于是直接调用wget下载,但是由于标准输出.错误输出的原因会导致卡住,另外wget也会莫名的卡住. 所以 ...

  2. shell变量自增的几种方式

    #!/bin/sh a= a=$(($a+)) a=$[$a+] a=`` let a++ let a+= ((a++)) echo $a 输出 : 转载自:http://blog.csdn.net/ ...

  3. Java注解基本原理

    注解目前非常的流行,很多主流框架都支持注解,而且自己编写代码的时候也会尽量的去用注解,一时方便,而是代码更加简洁. 注解的语法比较简单,除了@符号的使用之外,它基本与Java固有语法一致.Java S ...

  4. c++对象模型之Data布局

    Data语意学 class X{}; class Y : publicvirtual X {}; class Z : publicvirtual X {}; class A : publicY, pu ...

  5. python批量改动指定文件夹文件名称

    这小样例仅仅要是说明用python怎么批量改动指定文件夹的文件名称: 记得要把脚本跟改动的文件放在同一个文件夹下 #encoding:utf-8 import os import sys files ...

  6. 标C编程笔记day06 动态分配内存、函数指针、可变长度參数

    动态分配内存:头文件 stdlib.h     malloc:分配内存     calloc:分配内存,并清零     realloc:调整已分配的内存块大小     演示样例:         in ...

  7. UITableView显示不全

    先上图(不全图片): 正确图片: 原因例如以下: 1.在tableView的父视图的freme问题. 2.tableView本身的frame问题.大小依据自己的实际情况改过来就OK了 希望能够帮助到你 ...

  8. Android 快速开发系列 打造万能的ListView GridView 适配器

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38902805 ,本文出自[张鸿洋的博客] 1.概述 相信做Android开发的写 ...

  9. RHEL7查看网卡配置命令ip addr show

    Validating Network Address Configuration To verify the configuration of the network address, you nee ...

  10. ASP.NET-FineUI开发实践-5

    1.tree的右键事件和单击事件 页面就不写了,准备一个树和一个菜单控件,随便写点啥 JS:注意注释 var menuSettings = F('menuSettings'); var tree = ...