GestureDetectorCompat
class GestureDetectorCompat
kotlin.Any | |
↳ | androidx.core.view.GestureDetectorCompat |
Detects various gestures and events using the supplied MotionEvent
s. The OnGestureListener
callback will notify users when a particular motion event has occurred. This class should only be used with MotionEvent
s reported via touch (don't use for trackball events).
This compatibility implementation of the framework's GestureDetector guarantees the newer focal point scrolling behavior from Jellybean MR1 on all platform versions.
To use this class:- Create an instance of the
GestureDetectorCompat
for yourView
- In the
View#onTouchEvent(MotionEvent)
method ensure you callonTouchEvent(MotionEvent)
. The methods defined in your callback will be executed when the events occur.
Summary
Public constructors |
|
---|---|
<init>(context: Context!, listener: OnGestureListener!) Creates a GestureDetectorCompat with the supplied listener. |
|
<init>(context: Context!, listener: OnGestureListener!, handler: Handler!) Creates a GestureDetectorCompat with the supplied listener. |
Public methods |
|
---|---|
Boolean | |
Boolean |
onTouchEvent(event: MotionEvent!) Analyzes the given motion event and if applicable triggers the appropriate callbacks on the |
Unit |
setIsLongpressEnabled(enabled: Boolean) Set whether longpress is enabled, if this is enabled when a user presses and holds down you get a longpress event and nothing further. |
Unit |
setOnDoubleTapListener(listener: OnDoubleTapListener!) Sets the listener which will be called for double-tap and related gestures. |
Public constructors
<init>
GestureDetectorCompat(context: Context!, listener: OnGestureListener!)
Creates a GestureDetectorCompat with the supplied listener. As usual, you may only use this constructor from a UI thread.
Parameters | |
---|---|
context |
Context!: the application's context |
listener |
Context!: the listener invoked for all the callbacks, this must not be null. |
See Also
<init>
GestureDetectorCompat(context: Context!, listener: OnGestureListener!, handler: Handler!)
Creates a GestureDetectorCompat with the supplied listener. As usual, you may only use this constructor from a UI thread.
Parameters | |
---|---|
context |
Context!: the application's context |
listener |
Context!: the listener invoked for all the callbacks, this must not be null. |
handler |
Context!: the handler that will be used for posting deferred messages |
See Also
Public methods
isLongpressEnabled
fun isLongpressEnabled(): Boolean
Return | |
---|---|
Boolean: true if longpress is enabled, else false. |
onTouchEvent
fun onTouchEvent(event: MotionEvent!): Boolean
Analyzes the given motion event and if applicable triggers the appropriate callbacks on the OnGestureListener
supplied.
Parameters | |
---|---|
event |
MotionEvent!: The current motion event. |
Return | |
---|---|
Boolean: true if the OnGestureListener consumed the event, else false. |
setIsLongpressEnabled
fun setIsLongpressEnabled(enabled: Boolean): Unit
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 | |
---|---|
enabled |
Boolean: whether longpress should be enabled. |
setOnDoubleTapListener
fun setOnDoubleTapListener(listener: OnDoubleTapListener!): Unit
Sets the listener which will be called for double-tap and related gestures.
Parameters | |
---|---|
listener |
OnDoubleTapListener!: the listener invoked for all the callbacks, or null to stop listening for double-tap gestures. |