Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd zoom to an imageview in Android
    text
    copied!<p>I want to add zoom in my Android app. I have tried this code, but it just zooms in and out in the middle of the image and I want to apply the zoom on the whole image.</p> <p>In the same image, can I put a button in some areas in the image?</p> <pre><code>import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.view.KeyEvent; 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 you 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&lt;10) zoomControler=10; invalidate(); return true; } } </code></pre> <p>And this code</p> <pre><code>import android.app.Activity; import android.os.Bundle; public class zooming extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(new Zoom(this)); } } </code></pre> <p>How do I fix this problem?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload