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).
参考文章:
Android - GestureDetector 实现界面左右滑动效果的优化
Android GestureDetector简单手势检测(左右滑动、上下滑动)