6

I have an ImageView declared in main.XML . I want it to be Zoomed . How can this be done in Android?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Android_programmer_camera
  • 13,197
  • 21
  • 67
  • 81
  • http://stackoverflow.com/questions/1939103/how-to-make-my-imageview-zoomable , http://stackoverflow.com/questions/1939103/how-to-make-my-imageview-zoomable – ArK Oct 22 '10 at 10:15

1 Answers1

2

get it here

 public class Zoom extends View {
    private Drawable image;
    private int zoomControler=200;
    public Zoom(Context context)
    {
    super(context);
    image=context.getResources().getDrawable(R.drawable.gallery_photo_1);
    setFocusable(true);
    }
    @Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    //here u can control the width and height of the images........ this line is very important
    image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
    image.draw(canvas);
    }
    @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;
    invalidate();
    return true;
    }
    }
ArK
  • 20,698
  • 67
  • 109
  • 136
  • 3
    But I have an image in Layout ,I will get the reference of that ImageView using findViewById() and I want to zoom it dynamically. Assuming its is vertical LinearLayout , I have some other widgets below this this ImageView. How to do Zooming dynamically in Activity? – Android_programmer_camera Oct 22 '10 at 10:58