我正在使用touchImageView进行放大和缩小。除非我捏了捏,否则一切正常,imageview变得比原来的宽度和高度小。如何预防呢?因此当imageview未缩放时,用户无法捏住。
我到目前为止所做的
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
setState(State.ZOOM);
return true;
}
@Override
public boolean onScale(ScaleGestureDetector detector) {
// check pinch and out, but detector.getFocusX() > 320 && detector.getFocusY() > 220 not working for all conditions
if (detector.getScaleFactor() > 1) {
scaleImage(detector.getScaleFactor(), detector.getFocusX(), detector.getFocusY(), true);
}else {
if (detector.getFocusX() > 320 && detector.getFocusY() > 220){
scaleImage(detector.getScaleFactor(), detector.getFocusX(), detector.getFocusY(), true);
}
}
//
// OnTouchImageViewListener is set: TouchImageView pinch zoomed by user.
//
if (touchImageViewListener != null) {
touchImageViewListener.onMove();
}
return true;
}
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
super.onScaleEnd(detector);
setState(State.NONE);
boolean animateToZoomBoundary = false;
float targetZoom = normalizedScale;
if (normalizedScale > maxScale) {
targetZoom = maxScale;
animateToZoomBoundary = true;
} else if (normalizedScale < minScale) {
targetZoom = minScale;
animateToZoomBoundary = true;
}
if (animateToZoomBoundary) {
DoubleTapZoom doubleTap = new DoubleTapZoom(targetZoom, viewWidth / 2, viewHeight / 2, true);
compatPostOnAnimation(doubleTap);
}
}
}