Zooming in android - keep image in view

DILEMNE

New Member
I know there are tons of threads on actually getting pinch zoom implemented - but I got this far already.I'm using SimpleScaleGestureListener to handle the pinching. I've managed to make sure you can't zoom out farther than to keep the image height the same as the screen size (so you're image height will always be at least the height of the available screen size).However, I'm looking for a way to automatically detect if the image is being panned outside of these boundaries. Just like the standard android way of displaying the image. So if I zoom in, and pan the image up, and then zoom out, I want it to detect when the bottom of the image reaches the bottom of the screen, and then 'pivot' of the zooming adjusts accordingly, thus never allowing "whitespace" above or below the image itself. Can anyone help me?For reference, here's my onScale and onDraw methods:\[code\]public boolean onScale(ScaleGestureDetector detector){ float minScale = (float) ((float) SCREEN_SIZE.y / (float) DRAWABLE_SIZE.y); mScaleFactor *= detector.getScaleFactor(); mScaleFactor = Math.max(minScale, Math.min(mScaleFactor, 5.0f)); invalidate(); return true;}protected void onDraw(Canvas canvas) { canvas.save(); canvas.drawColor(Color.DKGRAY); canvas.translate(mPosX, mPosY); canvas.scale(mScaleFactor, mScaleFactor, getDrawable().getIntrinsicWidth() / 2, getDrawable().getIntrinsicHeight() / 2); this.getDrawable().draw(canvas); canvas.restore();}\[/code\]
 
Top