我知道实际上实现捏缩放有很多线程 - 但我已经做到了这一点。
我正在使用 SimpleScaleGestureListener 来处理捏合。我已经设法确保你不能缩小比保持图像高度与屏幕尺寸相同(所以你的图像高度总是至少是可用屏幕尺寸的高度)。
但是,我正在寻找一种方法来自动检测图像是否被平移到这些边界之外。就像显示图像的标准 android 方式一样。因此,如果我放大并向上平移图像,然后缩小,我希望它检测图像底部何时到达屏幕底部,然后相应地调整缩放的“枢轴”,因此永远不允许“图像本身上方或下方的空白”。谁能帮我?
作为参考,这是我的 onScale 和 onDraw 方法:
public boolean onScale(ScaleGestureDetector detector){
float minScale = (float) ((float) SCREEN_SIZE.y / (float) DRAWABLE_SIZE.y);
mScaleFactor *= detector.getScaleFactor();
mScaleFactor = Math.max(minScale, Math.min(mScaleFactor, 5.0f));
invalidate();
return true;
}
protected void onDraw(Canvas canvas) {
canvas.save();
canvas.drawColor(Color.DKGRAY);
canvas.translate(mPosX, mPosY);
canvas.scale(mScaleFactor, mScaleFactor, getDrawable().getIntrinsicWidth() / 2,
getDrawable().getIntrinsicHeight() / 2);
this.getDrawable().draw(canvas);
canvas.restore();
}