Android Gestures


Android Gestures


Android Gestures – In this chapter, you will learn following:

Gestures control

Android Gestures

Android Gestures App

Android Gestures List

Android Gestures Setting

Android Custom Gestures

Android Gestures Library

How To Use Android Gestures

Swipe Gestures Example

Here are 8 gestures you can use on Android that you might not know about.
  • 1) Two-finger swipe down.
  • 2) Press and hold on notifications.
  • 3) Press and hold to select.
  • 4) Swipe down from the Chrome address bar.
  • 5) Press and hold Power Off.
  • 6) Tap and hold the spacebar.
  • 7) Triple-tap to zoom in.
  • 8) Tap and hold on menus.

so lets we start our android gestures  you know tutorial that android facilitates different and special types of touch screen events e.g  double tab, long press, flinch and pinch. Yeah, you will know it nowadays everyone uses a smartphone and everyone knows that how is android gestures and how to use gestures in android. In some cases android apps ask users to double tap on the screen, sometimes they ask long press to copy the content and much more so these are android gestures. So if you don’t know about android gestures you will learn instantly. Just keep reading my android gestures tutorial I will teach everything that should know about android gestures

android facilitate GestureDetector class to receive movement events and reveal that these incidents match gestures or not. To put it to use , you need to generate an object of GestureDetector and prolong another class with GestureDetector.SimpleOnGestureListener to do something as a listener and override some methods. Its syntax is listed below

GestureDetector myG;
myG = new GestureDetector(this,new Gesture());
class Gesture extends GestureDetector.SimpleOnGestureListener{
   public boolean onSingleTapUp(MotionEvent ev) {
   public void onLongPress(MotionEvent ev) {
   public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
   float distanceY) {
   public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
   float velocityY) {


Android Handling Pinch Gestures

Android os provides ScaleGestureDetector class to take care of gestures like pinch. To be able to use it, you will need to instantiate an object of this class. Its syntax is given below

ScaleGestureDetector SGD;
SGD = new ScaleGestureDetector(this,new ScaleListener());


The first parameter is the context and the next parameter is the function listener. We must define the function listener and override a function OnTouchEvent to make it working. Its syntax is listed below

public boolean onTouchEvent(MotionEvent ev) {
   return true;

private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
   public boolean onScale(ScaleGestureDetector detector) {
      float scale = detector.getScaleFactor();
      return true;


Android Gestures Example

Here is a good example of android gestures demonstrating the utilization of ScaleGestureDetector class. It creates a simple application which allows you to focus in and out through pinch.

To test out this android gestures example , you can run this on a genuine device or within an emulator with touchscreen enabled.


      Steps     Description

  1. You use Android studio to generate an Android request under a deal com.example.sappal.myapplication.
  2. Modify src/ data file to include necessary code.
  3. Modify the res/design/activity_main to include respected XML components
  4. Run the application form and choose a operating google android device and mount the application onto it and check the results

Following is this content of the revised main activity data file src/

package com.example.sappal.myapplication;

import android.os.Bundle;

import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.widget.ImageView;

public class MainActivity extends Activity {
   private ImageView iv;
   private Matrix matrix = new Matrix();
   private float scale = 1f;
   private ScaleGestureDetector SGD;

   protected void onCreate(Bundle savedInstanceState) {

      SGD = new ScaleGestureDetector(this,new ScaleListener());

   public boolean onTouchEvent(MotionEvent ev) {
      return true;

   private class ScaleListener extends ScaleGestureDetector.
      SimpleOnScaleGestureListener {
      public boolean onScale(ScaleGestureDetector detector) {
         scale *= detector.getScaleFactor();
         scale = Math.max(0.1f, Math.min(scale, 5.0f));
         matrix.setScale(scale, scale);
         return true;


Following is the modified content of the xml res/layout/activity_main.xml.

Do You Have Any Question About This Tutorial? Ask Question Now On Andro Development & Get Answer Instantly. No Signup/Login Needed

Here abc indicates the logo of androdevelopment

   tools:context=".MainActivity" >
   <TextView android:text="Gestures  
      Example" android:layout_width="wrap_content"
      android:layout_centerHorizontal="true" />
      android:text="Andro Development"
      android:textSize="35dp" />
      android:layout_alignParentEnd="true" />

Following is the content of the res/values/string.xml.

   <string name="app_name>My Application</string>

Following is the content of AndroidManifest.xml file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
   package="com.example.sappal.myapplication" >

      android:theme="@style/AppTheme" >
         android:label="@string/app_name" >
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />


Let’s make an effort to run the application. I suppose you have linked your actual Android os Mobile device with your personal computer. To perform the software from Android studio room, available one of your project’s activity data files and click Run Eclipse Run Icon from the toolbar.The test output should end up like this

android gestures

Now just place two hands over android display , and distinct them the right part and you’ll note that the android image is zooming. It really is shown in the image below

android gestures

Now again place two fingertips over android display screen, and make an effort to close them and you’ll notice that the android image is currently shrinking. It really is shown in the image below –

android gestures

Do You Have Any Question About This Tutorial? Ask Question Now On Andro Development & Get Answer Instantly. No Signup/Login Needed