Android Swipe Gesture

Android Swipe Gesture

The Android SDK supports a variety of gestures you can detect, allowing you to tailor the ways in which users interact with your applications. In this tutorial, we will look at the framework that allows developers to add gesture detection to a simple application, working through the process of supporting the fling gesture and outlining how to support other gestures. Once you’ve completed the development for a basic fling function, you’ll be able to add additional gestures to the application yourself.

Example

In this tutorial, we are going to learn how to implement various swipe gestures in an app.

Video Demo

1. Create a new project in Android Studio by navigating to File ⇒ New Android ⇒ Application Project and fill required details. By default my activity is ShareActivity.java.

2. First create an xml layout file naming activity_main.xml that contains several imageview indicating type of gestures that a user can do.

3. Now create a java class naming SimpleGestureFilter.java that conatins various Gesture detector methods that we can use in our activity to recognize user gesture. You can modify this class according to your need.

4. Finally come to your MainActivity.java and add the following code. In this class we do several things listed below:

  • Implement SimpleGestureListener interface to listen user gesture.
  • Make an instance of SimpleGestureFilter class that we had created above.
  • Finally use onSwipe(int direction) and onDoubleTap method to do your stuff.
5. Now, you are all done, run your app and you will get the output as shown in video.

Thanks. :)

Download Source Code – >

 

Leave a Comment

Comment (required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Name (required)
Email (required)