Search This Blog

Saturday 6 April 2013

Update Pinch to zoom example and tutorial for android ImageView with zoom limit

I wrote on the same topic Pinch to zoom in android ImageView while i just started blogging. And that still is my one of the popular article, despite that it has many complication and limitation with it. So i am working to improve it. After reading most comment, I feel some problems while implementing pinch to zoom with android ImageView using previous post
  • How to implement that pinch to zoom in their project? 
  • Determining Zoom limit in pinch to zoom ImageView! 
  • Does not work properly as i told in post !! 

So now i come up with a solution in which every drawback avoided and pinch to zoom image in android seems quite simple and work perfect
Follows thes easy steps

1) Create a new project and Download this library , add this Jar to libs folder of your project 

2) Create one layout with one ImageView (Which need to be zoom)

3) Create one Activity and change to following code. This will handle all attributes required for pinch to zoom ImageView

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.imagezoom.ImageAttacher;
import com.imagezoom.ImageAttacher.OnMatrixChangedListener;
import com.imagezoom.ImageAttacher.OnPhotoTapListener;

public class SampleZoom extends Activity {
    ImageView mImaView;

    protected void onCreate(Bundle savedInstanceState) {
        mImaView = (ImageView) findViewById(;

        Bitmap bimtBitmap = BitmapFactory.decodeResource(getResources(),

         * Use Simple ImageView


    public void usingSimpleImage(ImageView imageView) {
        ImageAttacher mAttacher = new ImageAttacher(imageView);
        ImageAttacher.MAX_ZOOM = 2.0f; // Double the current Size
        ImageAttacher.MIN_ZOOM = 0.5f; // Half the current Size
        MatrixChangeListener mMaListener = new MatrixChangeListener();
        PhotoTapListener mPhotoTap = new PhotoTapListener();

    private class PhotoTapListener implements OnPhotoTapListener {

        public void onPhotoTap(View view, float x, float y) {

    private class MatrixChangeListener implements OnMatrixChangedListener {

        public void onMatrixChanged(RectF rect) {


Implementing Zoom Limit. 

See inside function usingSimpleImage(), below two line decide zoom limit ImageAttacher.MAX_ZOOM = 2.0f;  // Double the current Size ImageAttacher.MIN_ZOOM = 0.5f; // Half the current Size

Note : Work perfect for the image with fit width (either in Landscape or portrait)


  1. Hi wishy, I know the link i had given open some weird pop up but o had no other option for online storage to store. And i check it, it works fine. Just follow proper way. For now i have only this option. Hope you understand

  2. I apologize for jar.exe, My all data was corrupted on Ziddu. Now i am using drop-box and eventually i replace this jar with new link. and trying to replace others also. So check again this jar and Let me know


Feedback always help in improvement. If you have any query suggestion feel free to comment and Keep visiting my blog to encourage me to blogging

Android News and source code