My layout contains buttons, textviews, etc. Is it possible to implement pinch zoom in my layout?
Tap anywhere on the screen, except the keyboard or navigation bar. Drag 2 fingers to move around the screen. Pinch with 2 fingers to adjust zoom. To stop magnification, use your magnification shortcut again.
In the Hardware and Sound window, under Devices and Printers, click Mouse. In the Mouse Properties window, click the Multitouch Gestures tab. On the Multitouch Gestures tab, locate the Enable Pinch Zoom check box. Once the box is either checked or unchecked, click OK.
Pinch to zoom stopped working on Android. If pinch to zoom is not working on Chrome's web content, check the Accessibility settings. On the other hand, if pinch to zoom is not working at all you can always increase touch sensitivity or remove the screen protector.
Updated Answer
Code can be found here : official-doc
Answer Outdated
Check out the following links which may help you
Best examples are provided in the below links, which you can refactor to meet your requirements.
implementing-the-pinch-zoom-gestur
Android-pinch
GestureDetector.SimpleOnGestureListener
For android 2.2+ (api level8), you can use ScaleGestureDetector.
you need a member:
private ScaleGestureDetector mScaleDetector;
in your constructor (or onCreate()) you add:
mScaleDetector = new ScaleGestureDetector(context, new OnScaleGestureListener() { @Override public void onScaleEnd(ScaleGestureDetector detector) { } @Override public boolean onScaleBegin(ScaleGestureDetector detector) { return true; } @Override public boolean onScale(ScaleGestureDetector detector) { Log.d(LOG_KEY, "zoom ongoing, scale: " + detector.getScaleFactor()); return false; } });
You override onTouchEvent:
@Override public boolean onTouchEvent(MotionEvent event) { mScaleDetector.onTouchEvent(event); return true; }
If you draw your View by hand, in the onScale() you probably do store the scale factor in a member, then call invalidate() and use the scale factor when drawing in your onDraw(). Otherwise you can directly modify font sizes or things like that in the onScale().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With