ImageView Pinch-zoom Scale Limits and pan bounds

前端 未结 4 1166
心在旅途
心在旅途 2020-12-14 23:03

I wanted to create a 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 l

4条回答
  •  忘掉有多难
    2020-12-14 23:51

    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);
        }
    }
    ....        
    

提交回复
热议问题