-1

I have a code which zooms and pans the imageview matrix, it works well but i want the imageview to not be zoomed smaller than my screen, and i don't want it to be zoomed very much, i want to set a limit for zooming and to the same thing for dragging(panning) it should pan horizontally if image's width is larger than screen, and it should pan vertically if image's height is larger than the screen, how can i achieve this result ? i tried some methods from mike Ortiz's but i couldn't get them to work.

Blerim Blerii
  • 223
  • 3
  • 16

2 Answers2

1

I coded this for my app, and it's tricky to get it all right.

I created some Rects and RectFs to do a lot of the interim calculations right off the bat. It's more efficient when you don't have to allocate these on every operation.

I used Matrix.setRectToRect() to find the minimum scale factor, and 3x that for the maximum. Then after the postScale on zoom, I clamp the new [absolute] scale factor to min/max.

Also after the postScale, I also compare the rect coordinates to the screen coordinates and add a translation to keep the image corners outside the screen boundaries. This same logic is also done for dragging operations.

kris larson
  • 30,387
  • 5
  • 62
  • 74
0

look into this library

https://github.com/davemorrissey/subsampling-scale-image-view

Highly configurable, easily extendable view with pan and zoom gestures for displaying huge images without loss of detail. Perfect for photo galleries, maps, building plans etc.

Ravi Gadipudi
  • 1,446
  • 1
  • 17
  • 30