我想使用缩放手势在水平或垂直方向上在画布上缩放位图。我试过样品,但保持纵横比。但我只想垂直缩放或水平缩放。
答案 0 :(得分:0)
我以某种方式解决了我的问题。这就是我在做什么。如果有人有更好的解决方案,请告诉我。 谢谢
私有类ScaleListener扩展ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
float xScale = detector.getCurrentSpanX() / detector.getPreviousSpanX();
float yScale = detector.getCurrentSpanY() / detector.getPreviousSpanY();
float diffSpanX = detector.getCurrentSpan() - detector.getPreviousSpanX();
float diffSpanY = detector.getCurrentSpan() - detector.getPreviousSpanY();
/**
* Ignore scaleX
*/
if (diffSpanX > diffSpanY) {
scaleFactorY *= yScale;
scaleFactorY = Math.max(0.1f, Math.min(scaleFactorY, 5.0f));
} else {
scaleFactorX *= xScale;
scaleFactorX = Math.max(0.1f, Math.min(scaleFactorX, 5.0f));
}
update(scaleFactorX, scaleFactorY);
return true;
}
}