Avi Kumar
Avi Kumar

Reputation: 4433

How to increase or decrease the size of image on button in android?

I have made an android application in which I have few images. I had implemented on touch functionality in it user can move back and forth with on touch. Now I want to zoom the image on button click.Any suggestion or tutorial how to zoom in and zoom out on button click will be helpful.

Upvotes: 0

Views: 2992

Answers (2)

Sunil Kumar Sahoo
Sunil Kumar Sahoo

Reputation: 53647

Check the following links to zoom an image

http://vinnysoft.blogspot.com/2009/08/zooming-imageview.html

or

http://blogs.sonyericsson.com/wp/2010/05/18/android-one-finger-zoom-tutorial-part-1/

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;
    }
    }

Thanks Deepak

Upvotes: 2

Related Questions