没有合适的资源?快使用搜索试试~ 我知道了~
GestureDetector和SimpleOnGestureListener的使用教程
需积分: 50 29 下载量 92 浏览量
2011-09-28
20:25:12
上传
评论
收藏 17KB DOCX 举报
温馨提示
试读
5页
通过GestureDetector的构造方法可以将SimpleOnGestureListener对象传递进去,这样GestureDetector能处理不同的手势了。
资源推荐
资源详情
资源评论
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 方法源码
资源评论
dadahai87
- 粉丝: 2
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功