Android SDK | API level 24 | GestureDetector

来源:互联网 发布:python 函数传递对象 编辑:程序博客网 时间:2024/06/18 06:53

GestureDetector

public class GestureDetector 
extends Object 

java.lang.Object   ↳android.view.GestureDetector

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:

  • Create an instance of the GestureDetector for your View
  • In the onTouchEvent(MotionEvent) method ensure you call onTouchEvent(MotionEvent). The methods defined in your callback will be executed when the events occur.
  • If listening for onContextClick(MotionEvent) you must call onGenericMotionEvent(MotionEvent) in onGenericMotionEvent(MotionEvent).

使用提供的MotionEvents检测各种手势和事件。

当某个特定的运动事件发生时,回调函数GestureDetector.OnGestureListener将会通知用户。

这个类只应用于触摸事件,而不应用于追踪事件。为了使用这个类:

1、为你的View创建一个GestureDetector句柄。

2、在onTouchEvent(MotionEvent)方法里面,确保你调用了onTouchEvent(MotionEvent)。回调中定义的方法,将在事件发生时执行。

3、如果监听onContextClick(MotionEvent),你必须在onGenericMotionEvent(MotionEvent)中调用onGenericMotionEvent(MotionEvent)。

Summary


Nested classes 嵌套类interfaceGestureDetector.OnContextClickListenerThe listener that is used to notify when a context click occurs. 
此监听器用来通知context的click事件。interfaceGestureDetector.OnDoubleTapListenerThe listener that is used to notify when a double-tap or a confirmed single-tap occur. 
此监听器用来通知双击或者单击确认事件。interfaceGestureDetector.OnGestureListenerThe listener that is used to notify when gestures occur. 
此监听器用来监听手势事件。classGestureDetector.SimpleOnGestureListenerA convenience class to extend when you only want to listen for a subset of all the gestures. 
当你只想监听所有手势事件的一个部分时,可以继承这个方便的类。




Inherited methods 继承方法
 java.lang.Object类中的方法

Public Constructors


GestureDetector

Added in API level 1
GestureDetector (GestureDetector.OnGestureListener listener, Handler handler)

This constructor was deprecated in API level 3.
Use GestureDetector(android.content.Context, android.view.GestureDetector.OnGestureListener, android.os.Handler) instead.

Creates a GestureDetector with the supplied listener. This variant of the constructor should be used from a non-UI thread (as it allows specifying the Handler).

和所提供的listener一起创建一个GestureDetector 。这个版本的构造函数应该用于非UI线程上(因为它允许指定Handle)。


GestureDetector

Added in API level 1
GestureDetector (GestureDetector.OnGestureListener listener)

This constructor was deprecated in API level 3.
Use GestureDetector(android.content.Context, android.view.GestureDetector.OnGestureListener) instead.

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

和被提供的listener一起创建一个GestureDetector。你可以只在UI线程上使用这个构造函数(这是一般情况)。



GestureDetector

Added in API level 3
GestureDetector (Context context, GestureDetector.OnGestureListener listener)

Creates a GestureDetector with the supplied listener. You may only use this constructor from a Looper thread.

使用提供的listener一起创建一个GestureDetector。你可以只在Looper线程上使用这个构造函数。


GestureDetector

Added in API level 3
GestureDetector (Context context, GestureDetector.OnGestureListener listener, Handler handler)

Creates a GestureDetector with the supplied listener that runs deferred events on the thread associated with the supplied Handler.

和在handler(参数中提供的)相关线程上运行延迟时间的listener(参数中提供的)一起,创建一个GestureDetector。




GestureDetector

Added in API level 8
GestureDetector (Context context, GestureDetector.OnGestureListener listener, Handler handler, boolean unused)

Creates a GestureDetector with the supplied listener that runs deferred events on the thread associated with the supplied Handler.

和在handler(参数中提供的)相关线程上运行延迟时间的listener(参数中提供的)一起,创建一个GestureDetector。



Public methods


isLongpressEnabled

Added in API level 1
boolean isLongpressEnabled ()
Returnsbooleantrue if longpress is enabled,else false. 如果长按是有效的是true,否则为false。

onGenericMotionEvent

Added in API level 23
boolean onGenericMotionEvent (MotionEvent ev)

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

分析给定的通用运动事件,并分析是否适当触发了GestureDetector.OnGestureListener提供的相应的回调函数。

ParametersevMotionEvent: The current motion event.Returnsbooleantrue if the GestureDetector.OnGestureListener consumed the event, else false.
如果GestureDetector.OnGestureListener监听到了事件,则是真的,否则为假。

onTouchEvent

Added in API level 1
boolean onTouchEvent (MotionEvent ev)

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

分析给定的通用运动事件,并分析是否适当触发了GestureDetector.OnGestureListener提供的相应的回调函数。

ParametersevMotionEvent: The current motion event.Returnsbooleantrue if the GestureDetector.OnGestureListener consumed the event, else false.
如果GestureDetector.OnGestureListener监听到了事件,则是真的,否则为假。

setContextClickListener

Added in API level 23
void setContextClickListener (GestureDetector.OnContextClickListener onContextClickListener)

Sets the listener which will be called for context clicks.

设置context clicks的监听器。


setIsLongpressEnabled

Added in API level 1
void setIsLongpressEnabled (boolean isLongpressEnabled)

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.

设置长按是否可用,如果可用,当用户按下并保持按下下滑的时候,你会接收到一个长按事件,并无其他。如果是不可用的,则用户可以按下和保持按下下滑,然后过了一会移开手指,会得到滑动事件。默认长按是可用的。

ParametersisLongpressEnabledboolean: whether longpress should be enabled.
boolean: 是否长按是可用的。

setOnDoubleTapListener

Added in API level 3
void setOnDoubleTapListener (GestureDetector.OnDoubleTapListener onDoubleTapListener)

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

为双击和相关手势设置监听器。



翻译有不足之处,欢迎指正~

原创粉丝点击