Component - Gesture handling
This UI component detects user touch gestures like taps and swipes on the screen. It responds by updating the display to show which gesture was recognized.
This UI component detects user touch gestures like taps and swipes on the screen. It responds by updating the display to show which gesture was recognized.
FrameLayout
└── GestureDetectorView
└── TextViewGestureDetector in Android Kotlin apps?GestureDetector is designed to listen for user touch gestures such as taps, swipes, and long presses on views.GestureDetector with a simple gesture listener in Kotlin?val detector = GestureDetector(this, object : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapUp(e: MotionEvent?): Boolean {
println("Tapped")
return true
}
})
view.setOnTouchListener { _, event ->
detector.onTouchEvent(event)
true
}
What will happen when the user taps on the view?val detector = GestureDetector(this, object : GestureDetector.SimpleOnGestureListener() {
override fun onLongPress(e: MotionEvent?) {
println("Long press detected")
}
})
view.setOnTouchListener { _, event ->
detector.onTouchEvent(event)
}Pass the test and this pattern moves unknown