我遵循了一个关于如何缩放图像的简单教程。问题是我无法在缩放后拖动和缩放图像。我确实阅读了android Dragging和scalling并尝试了其他答案,但它不起作用。下面是放大图像的代码。有人可以在这里指导我吗?
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;
}