Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android pinch zoom

My layout contains buttons, textviews, etc. Is it possible to implement pinch zoom in my layout?

like image 693
Bytecode Avatar asked Mar 21 '11 09:03

Bytecode


People also ask

How do you pinch zoom on Android?

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.

How do I turn on pinch zoom?

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.

Why is my pinch zoom not working?

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.


2 Answers

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.

  1. implementing-the-pinch-zoom-gestur

  2. Android-pinch

  3. GestureDetector.SimpleOnGestureListener

like image 109
Vinayak Bevinakatti Avatar answered Sep 18 '22 12:09

Vinayak Bevinakatti


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().

like image 26
Emmanuel Touzery Avatar answered Sep 22 '22 12:09

Emmanuel Touzery