I followed a simple tutorial on how to zoom an image. The problem is i can't drag and scale the image after zooming it. i did read android Dragging and scalling and tried other answers but it doesn't work. below is the code for zooming in the image. Can someone guide me here?
public class MainActivity extends AppCompatActivity{
ImageView imageView;
Matrix matrix=new Matrix();
Float scale=1f;
ScaleGestureDetector SGD;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
imageView=(ImageView)findViewById(R.id.imageView);
SGD= new ScaleGestureDetector(this,new ScaleListener());
}
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener{
@Override
public boolean onScale(ScaleGestureDetector detector) {
scale= scale*detector.getScaleFactor();
scale= Math.max(0.1f,Math.min(scale,3f));
matrix.setScale(scale, scale);
imageView.setImageMatrix(matrix);
return true;
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
SGD.onTouchEvent(event);
return true;
}