GestureDetector

public class

GestureDetector

extends   Object
java.lang.Object
   ↳ android.view.GestureDetector

Class Overview

Detects various gestures and events using the supplied MotionEvents. The GestureDetector.OnGestureListener callback will notify users when a particular motion event has occurred. This class should only be used with MotionEvents reported via touch (don't use for trackball events). To use this class:

利用提供的MotionEvent来检测多种手势和事件。当一个特殊的动作事件发生,GestureDetector.OnGestureListener这个回调接口就会通知用户。这个类只能用于由触摸所引起的事件(不用于由轨迹球所引起的事件)。

为你的view创建GestureDetector实例

确保你调用了onTouchEvent(MotionEvent)。这个方法定义了当某一事件发生时回调方法会被执行。

public GestureDetector (Context context, GestureDetector.OnGestureListener listener)
Since:   API Level 3

Creates a GestureDetector with the supplied listener. You may only use this constructor from a UI thread (this is the usual situation).

Parameters
context the application's context
listener the listener invoked for all the callbacks, this must not be null.
Throws
NullPointerException if listener is null.
See Also

用存在的listener来创建GestureDetector。按照惯例来说,你只能在UI线程中调用这个构造方法。

listener不能为空。

public GestureDetector (Context context, GestureDetector.OnGestureListener listener, Handler handler, boolean ignoreMultitouch)
ignoreMultitouch whether events involving more than one pointer should be ignored.

是否忽视多点触摸

public boolean isLongpressEnabled ()
Since:   API Level 1
Returns
  • true if longpress is enabled, else false
  • 当长按有效的时候会返回true,否则返回false
  • public boolean onTouchEvent (MotionEvent ev)
    Since:   API Level 1

    Analyzes the given motion event and if applicable triggers the appropriate callbacks on the GestureDetector.OnGestureListener supplied.

    Parameters
    ev The current motion event.
    Returns
    分析事件,调用GestureDetector.OnGestureListener中合适的回调方法
  • 如果GestureDetector.OnGestureListener 处理了事件,就返回true,否则返回false
    public void setIsLongpressEnabled (boolean isLongpressEnabled)
    Since:   API Level 1

    Set whether longpress is enabled, if this is enabled when a user presses and holds down you get a longpress event and nothing further. If it's disabled the user can press and hold down and then later moved their finger and you will get scroll events. By default longpress is enabled.

    Parameters
    isLongpressEnabled whether longpress should be enabled.
    设置长按是否有效,默认情况下是有效的。如果长按无效,当用户长按后移动会引发滑动事件。
  • public void setOnDoubleTapListener (GestureDetector.OnDoubleTapListener onDoubleTapListener)
    Since:   API Level 3

    Sets the listener which will be called for double-tap and related gestures.

    Parameters
    onDoubleTapListener the listener invoked for all the callbacks, or null to stop listening for double-tap gestures.
    设置是否监听双击事件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值