ImageView Pinch-zoom Scale Limits and pan bounds

前端 未结 4 1155
心在旅途
心在旅途 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条回答
  •  -上瘾入骨i
    2020-12-14 23:31

    You can set zoom limit by adding these lines to ACTION_MOVE, mode == ZOOM:

    float[] f = new float[9];
    matrix.getValues(f);
    
    float scaleX = f[Matrix.MSCALE_X];
    float scaleY = f[Matrix.MSCALE_Y];
    if (scaleX > MAX_SCALE || scaleY > MAX_SCALE) return true;
    

    Similarly, add lines to ACTION_MOVE, mode == DRAG that takes into account the original location of your image, the translated length, and then compare them to the bounds.

提交回复
热议问题