没有合适的资源?快使用搜索试试~ 我知道了~
首页GestureDetector和SimpleOnGestureListener的使用教程
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/3644882/bg1.jpg)
1. 当用户触摸屏幕的时候,会产生许多手势,例如 down,up,scroll,ling 等等,
我们知道 View 类有个 View.OnTouchListener 内部接口,通过重写他的
onTouch(Viewv,MotionEventevent)方法,我们可以处理一些 touch 事件,
但是这个方法太过简单,如果需要处理一些复杂的手势,用这个接口就会很麻烦
(因为我们要自己根据用户触摸的轨迹去判断是什么手势)Android sdk 给我们
提供了 GestureDetector(Gesture:手势 Detector:识别)类,通过这个类我
们可以识别很多的手势,主要是通过他的 onTouchEvent(event)方法完成了不同
手势的识别。虽然他能识别手势,但是不同的手势要怎么处理,应该是提供给程序
员实现的,因此这个类对外提供了两个接口:
OnGestureListener,OnDoubleTapListener,还有一个内部类
SimpleOnGestureListener,SimpleOnGestureListener 类是
GestureDetector 提供给我们的一个更方便的响应不同手势的类,这个类实现了
上述两个接口(但是所有的方法体都是空的),该类是 static class,也就是说它
实际上是一个外部类。程序员可以在外部继承这个类,重写里面的手势处理方法。
通过 GestureDetector 的构造方法可以将 SimpleOnGestureListener 对象传递
进去,这样 GestureDetector 能处理不同的手势了。
2. 具体用法:
2.1
private class DefaultGestureListener extends
SimpleOnGestureListener{
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
/**
* @param e1 The rst down motion event that started the
scrolling.
@param e2 The move motion event that triggered the current
onScroll.
@param 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.
@param 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.
无论是用手拖动 view,或者是以抛的动作滚动,都会多次触发 ,
这个方法在 ACTION_MOVE 动作发生时就会触发 参看 GestureDetector 的
onTouchEvent 方法源码
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)