Alex
Alex

Reputation: 7521

How to limit minimum zoom to a screen size in Android application implementing multi-touch screen?

I use a code from “Hello Android” to implement a multi-touch screen. It allows drag gesture and pinch zoom.

The problem with this implementation is that a picture can become very small or be moved out from a screen. There is a solution that allows limiting zoom and pan (http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part-6-implementing-the-pinch-zoom-gesture/1847). It limits zoom but to a certain size. In the Android Gallery application a minimum size for a zoom is a screen size.

How to achieve this?

Upvotes: 1

Views: 2724

Answers (1)

Abhinav
Abhinav

Reputation: 39942

What you would ideally want is to limit the image width and height within the view bounds. You can get the bounds using the onSizeChanged method in your custom view.

Define a minScale (according to the view size) and a maxScale (according to the original image scale) and before you change the transformation matrix of the image, check whether the final scale falls within this range.

You will have to apply the same scale factor to both width and height to maintain the same aspect ratio.

--EDIT-- Had put this on Github: https://github.com/a85/WebComicViewer/blob/master/src/com/rickreation/ui/ZoomableImageView.java

Upvotes: 1

Related Questions