Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

8. Handling Gestures > Responding to Gestures

Responding to Gestures

Touch events provide a very low-level interface to the touchscreen that can be difficult to interpret. Often what you really need is the ability to recognize certain gestures the user makes on the screen. For that, Android provides convenience classes that detect gestures for you.

GestureDetector

To detect gestures, you create an instance of the GestureDetector class and send it all touch events your view receives. You register an OnGestureListener with the GestureDetector to receive callbacks when gestures are detected. This interface has callbacks for the most common gestures you will need: taps, double taps, swipes, and flings.

Modify the example to zoom the text when you double-tap the screen:

1. Add a scale field to the View. You will use this to scale the text size:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial