ImageView的捏缩放比例限制和平移范围 [英] ImageView Pinch-zoom Scale Limits and pan bounds

查看:194
本文介绍了ImageView的捏缩放比例限制和平移范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建图像的画廊。 画廊内的图像应该是可缩放和pannable。我可以能捏缩放图像,但能不能被摇出屏幕设置缩放限制和prevent图像。 我用下面的code放大图像: <一href="http://$c$c.google.com/p/4chan-image-browser/source/browse/src/se/robertfoss/MultiTouch/TouchImageView.java?spec=svnd3e623ddeb6f9e97d9eba2c7aaa7c4567a3822b5&r=d3e623ddeb6f9e97d9eba2c7aaa7c4567a3822b5" rel="nofollow">http://$c$c.google.com/p/4chan-image-browser/source/browse/src/se/robertfoss/MultiTouch/TouchImageView.java?spec=svnd3e623ddeb6f9e97d9eba2c7aaa7c4567a3822b5&r=d3e623ddeb6f9e97d9eba2c7aaa7c4567a3822b5

I wanted to create an gallery with images. The images within the gallery should be zoomable and pannable. I could able to pinch-zoom an image but could not able to set zoom limits and prevent the image from being panned off the screen. I used the following code to zoom an image: http://code.google.com/p/4chan-image-browser/source/browse/src/se/robertfoss/MultiTouch/TouchImageView.java?spec=svnd3e623ddeb6f9e97d9eba2c7aaa7c4567a3822b5&r=d3e623ddeb6f9e97d9eba2c7aaa7c4567a3822b5

第一种方法: 我用TouchImageView提供图像画廊,这让我捏放大,但 不能滚动画廊。即我不能单选项卡事件和选项卡,滚动事件区分开来。

First approach : I used TouchImageView to supply images to gallery, this allows me to pinch zoom but can't scroll the gallery. i.e I cant differentiate between 'single tab event' and 'tab to scroll event'.

第二条本办法: 二手ImageView的将图像提供给画廊,如果用户点击任何画廊项的TouchImageView,在这里用户可以捏,放大的图像显示选定的图像。但是,这也prevent我从滚动画廊视图。以及如何对所选图像设定缩放限制和平移界限?

Second approach : Used ImageView to supply images to gallery, and if user click on any of the gallery item display the selected image in TouchImageView, where user can Pinch-Zoom an image. But this also prevent me from scrolling the gallery view. And also how to set zoom limits and pan bounds on selected image?

推荐答案

本固定变焦限制我的问题。之后,图像被放大/缩小到了极限,它只是停止进一步去。它也平滑且没有滞后。 0.7和2.0的最小和最大缩放级别

This fixed the zoom-limit problem for me. After the image is zoomed in/out to the limit, it just stops going further. It's also smooth and there are no lags. 0.7 and 2.0 are the minimum and maximum zoom levels.

....
} else if (mode == ZOOM) {
    float[] f = new float[9];

    float newDist = spacing(event);
    if (newDist > 10f) {
            matrix.set(savedMatrix);
            float tScale = newDist / dist;
            matrix.postScale(tScale, tScale, mid.x, mid.y);
    }

    matrix.getValues(f);
    float scaleX = f[Matrix.MSCALE_X];
    float scaleY = f[Matrix.MSCALE_Y];

    if(scaleX <= 0.7f) {
            matrix.postScale((0.7f)/scaleX, (0.7f)/scaleY, mid.x, mid.y);
    } else if(scaleX >= 2.5f) {
            matrix.postScale((2.5f)/scaleX, (2.5f)/scaleY, mid.x, mid.y);
    }
}
....        

这篇关于ImageView的捏缩放比例限制和平移范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆