How to implement swipe gestures in android

I am new to Android. Here I want to implement Swipe Gesture to navigate between actions. I searched for it and found different answers on different sites. But I could not say for sure. Reading all of them, I realized that we need to implement onTouchEvent() and onFlingEvent() .

Are these functions sufficient to implement the Swipe action? Please indicate how to proceed step by step to implement swipe gestures.

Sorry if I asked you a very simple question, because I asked this question after a long attempt at many pieces of code.

Can anyone clarify my doubts?

+7
source share
2 answers

onTouchEvent enough. What do you want to do:

  • Create a VelocityTracker and submit it, tap the viewing results.
  • When you get an UP event, check how fast it was. If its greater than some threshold value in the X direction, which is considered a swipe.
  • Start a new action when you recognize it.

You may have to play a little with the threshold, otherwise a careless faucet might be mistaken for subport.

+7
source

If you want to scroll your view, you must use ViewFlipper . You can set onTouchListener to ViewFlipper. And you can register the GestureDetector with onTouchListener. Here is one good example of Android transitions being inserted and pushed .

+1
source

All Articles