I'm using the following code for zooming ,I achieved zooming functionality but after zoom the image move bottom right ,I also used the limit zoom function to limit the zoom,after attaining limited size it moves downwards and the code is,,
else if (mode == ZOOM)
{
// pinch zooming
float[] f = new float[9];
if (newDist > 10f) {
matrix.set(savedMatrix);
float tScale = newDist / oldDist;
matrix.postScale(tScale, tScale, mid.x, mid.y);
}
matrix.getValues(f);
float scaleX = f[Matrix.MSCALE_X];
float scaleY = f[Matrix.MSCALE_Y];
if(scaleX <= 0.7f)
matrix.postScale((0.7f)/scaleX, (0.7f)/scaleY, mid.x, mid.y);
else if(scaleX >= 2.5f)
matrix.postScale((2.5f)/scaleX, (2.5f)/scaleY, mid.x, mid.y);
limitDrag(matrix);
View view1 = mCropCircle;
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view1.getLayoutParams();
layoutParams.leftMargin = (int) ((minCircleX +(maxDragX/2))-100);
layoutParams.topMargin = (int) ((minCircleY +(maxDragY/2))-100);
view1.setLayoutParams(layoutParams);
}
break;
}
limitZoom(matrix);
view.setImageMatrix(matrix); // display the transformation on screen
return true;
private void limitZoom(Matrix m) {
float[] values = new float[9];
m.getValues(values);
float scaleX = values[Matrix.MSCALE_X];
float scaleY = values[Matrix.MSCALE_Y];
if(scaleX > MAX_ZOOM)
{
scaleX = MAX_ZOOM;
}
else if(scaleX < MIN_ZOOM)
{
scaleX = MIN_ZOOM;
}
if(scaleY > MAX_ZOOM)
{
scaleY = MAX_ZOOM;
}
else if(scaleY < MIN_ZOOM)
{
scaleY = MIN_ZOOM;
}
values[Matrix.MSCALE_X] = scaleX;
values[Matrix.MSCALE_Y] = scaleY;
m.setValues(values);
}