Responding to manipulation gestures

In some cases, an object needs to be manipulated on the screen. This can be done using the stretch action, and the most natural way to do this is to simply use a two-finger pinch gesture.

How to do it...

Adding support for pinch-to-zoom is just a matter of passing the touch events to an instance of ScaleGestureDetector and implementing the IOnScaleGestureListener interface:

  1. To support the pinch-to-zoom gesture, we need to first implement the ScaleGestureDetector.IOnScaleGestureListener interface:
    public class MyView : View, ScaleGestureDetector.IOnScaleGestureListener { public bool OnScaleBegin(ScaleGestureDetector detector) { return true; } public bool OnScale(ScaleGestureDetector detector) { return true; } public ...

Get Xamarin Mobile Development for Android Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.