You are changing the boundaries of the image, not changing the boundaries of the view. Try changing the height and width of the view. Then you can scroll.
You must override the onMeasure() method and set setMeasuredDimension to the current height and width. Maintain height and width as elements.
EDIT:
class YourView extends View { static Bitmap mOrignalBitmap = null; // check n load in constructor. @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); setMeasuredDimension(mWidth,mHeight); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Rect src = new Rect(0,0, originalWidth, originalHeight); Rect dst = new Rect(viewLeft, viewTop, viewRight, viewBottom); canvas.drawBitmap(mOrignalBitmap , src, dst, null); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode==KeyEvent.KEYCODE_DPAD_UP)// zoom in zoomControler+=10; if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // zoom out zoomControler-=10; if(zoomControler<10) zoomControler=10; mWidth = //set view width with zoom mHeight = // set view height with zoom. requestLayout(); return true; } }
source share