Android development: Implement gesture swiping function
First of all, Activity must implement the OnGestureListener interface, which provides some methods for gesture operation.
onDown method: onDown is, once the touch screen is pressed, an onDown event will be generated immediately.
public boolean onDown(MotionEvent e) { return false; }
- onFling method: Triggered when the hand slides on the screen but the hand does not leave the screen
- MotionEvent e1 The MotionEvent object at the position of the screen begins to touch
- MotionEvent e2 MotionEvent object where the hand ends touching the screen
- float velocityX indicates the speed of the hand moving in the horizontal direction
- float velocityX indicates the speed of the hand moving in the vertical direction
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
onLongPress method: Triggered when you press the screen for a long time
public void onLongPress(MotionEvent e)
onScroll method: triggered when the hand slides on the screen and leaves the screen. The parameters are the same as onFling (note the difference between the two)
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
onShowPress method: Click the touch screen, but there is no movement and popping action. The difference between onShowPress and onDown is that once the touch screen is pressed, an onDown event will be generated immediately. However, onShowPress is generated after the onDown event is generated. If there is no movement of the mouse and popping event for a period of time, it is considered to be an onShowPress event.
public void onShowPress(MotionEvent e)
onSingleTapUp method: After tapping the touch screen, it pops up. If onLongPress, onScroll and onFling events are produced during this process, onSingleTapUp events will not be generated.
public boolean onSingleTapUp(MotionEvent e)
If you have any questions, please leave a message or go to the community of this site to exchange and discuss. Thank you for reading. I hope it can help you. Thank you for your support for this site!