开发者

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

I use a code from开发者_StackOverflow中文版 “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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜