using ontouch to zoom in

Posted by user357032 on Stack Overflow See other posts from Stack Overflow or by user357032
Published on 2010-06-14T01:27:25Z Indexed on 2010/06/14 1:32 UTC
Read the original article Hit count: 437

Filed under:
|
|

i have used some sample code and am trying to tweak it to let me allow the user to touch the screen and zoom in the code runs fine with no errors but when i touch the screen nothing happens

package com.thomas.zoom;

import android.content.Context;

import android.graphics.Canvas;

import android.graphics.drawable.Drawable;

import android.view.KeyEvent;

import android.view.MotionEvent;

import android.view.View; public class Zoom extends View { private Drawable image;

    private int zoomControler=20;

    public Zoom(Context context)
    {
            super(context);
            image=context.getResources().getDrawable(R.drawable.icon);
            setFocusable(true);
}
    @Override
    protected void onDraw(Canvas canvas) {
            // TODO Auto-generated method stub
            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);
    }
    public boolean onTouch(int action, MotionEvent event) {
           action= event.getAction();
           if(action == MotionEvent.ACTION_DOWN){
               zoomControler+=10;               
               }
            invalidate();
            return true;
    }

}

© Stack Overflow or respective owner

Related posts about android

Related posts about zoom