Android Detect Gestures Tutorial

Gesture occurs when a user places one or more fingers on the touch screen, and your application interprets that pattern of touches as a particular gesture. Android provides special types of gestures such as pinch, double tap, scrolls, long presses and flinch. Android provides GestureDetector class to receive gestures events and tell us that these events occur in the smart phone. The purpose of the gesturedetector class is to Gathering data about touch events and Interpreting the data to see if it meets the criteria for any of the gestures your app supports. In this tutorial, I will tell you how to use android detect gestures in your new project.

Creating a New Project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “GesturesExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Empty Activity” and Click Next button
5. Lastly, press finish button.

Edit activity_main.xml layout

Add the textview inside the constraint-layout, add a new id for textview “txt_gesture” so that you can display the gesture status in the UI.

Edit MainActivity.java class

Go to MainActivity.java class and implements GestureDectector listeners, After that initialize all callbacks from the listeners. You can follow the sample below.

Run Your Project

In conclusion, now you can run this project in the device and test out all the gestures listener that you implement.

(Android Detect Gestures)

Source Code

(Visited 173 times, 1 visits today)
Advertisements

Kristofer Ng

A crazy android and web developer. Passion on developing android application and exploring new technology as a hobby.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *