简体   繁体   English

如何在实现多点触摸屏的Android应用程序中将最小缩放限制在屏幕尺寸上?

[英]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. 我使用“ Hello Android”中的代码来实现多点触摸屏。 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). 有一种解决方案可以限制缩放和平移(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. 在Android Gallery应用程序中,缩放的最小尺寸是屏幕尺寸。

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. 您可以在自定义视图中使用onSizeChanged方法获取界限。

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. 定义一个minScale(根据视图大小)和maxScale(根据原始图像比例),然后在更改图像的变换矩阵之前,检查最终比例是否在此范围内。

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 -编辑-已将其放在Github上: https : //github.com/a85/WebComicViewer/blob/master/src/com/rickreation/ui/ZoomableImageView.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM