Advance Pinch zoom in android ImageView
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.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.RectF;
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pinch_sample);
mImaView = (ImageView) findViewById(R.id.simple);
Bitmap bimtBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.a);
mImaView.setImageBitmap(bimtBitmap);
/**
* Use Simple ImageView
*/
usingSimpleImage(mImaView);
}
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();
mAttacher.setOnMatrixChangeListener(mMaListener);
PhotoTapListener mPhotoTap = new PhotoTapListener();
mAttacher.setOnPhotoTapListener(mPhotoTap);
}
private class PhotoTapListener implements OnPhotoTapListener {
@Override
public void onPhotoTap(View view, float x, float y) {
}
}
private class MatrixChangeListener implements OnMatrixChangedListener {
@Override
public void onMatrixChanged(RectF rect) {
}
}
}
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.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.RectF;
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pinch_sample);
mImaView = (ImageView) findViewById(R.id.simple);
Bitmap bimtBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.a);
mImaView.setImageBitmap(bimtBitmap);
/**
* Use Simple ImageView
*/
usingSimpleImage(mImaView);
}
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();
mAttacher.setOnMatrixChangeListener(mMaListener);
PhotoTapListener mPhotoTap = new PhotoTapListener();
mAttacher.setOnPhotoTapListener(mPhotoTap);
}
private class PhotoTapListener implements OnPhotoTapListener {
@Override
public void onPhotoTap(View view, float x, float y) {
}
}
private class MatrixChangeListener implements OnMatrixChangedListener {
@Override
public void onMatrixChanged(RectF rect) {
}
}
}
Comments
Post a Comment