首先让我说我已经阅读了大量的缩放问题并在这里重新计算坐标。但我似乎无法将它们应用于我的情况。
我有一个可以缩放和滚动的自定义 ImageView 类。我遇到的问题来自按此顺序执行以下操作:
- 放大一个点,并使用该点作为焦点(这有效)
- 在放大的同时滚动
- 尝试在不同的点上放大/缩小(不起作用)
这是自定义视图的示例。有两个圆圈:红色和绿色。红色是焦点应该在的位置,绿色是焦点接近实际位置的位置。

当我尝试放大橙色圈出的区域时,就会出现问题。在下图中,我尝试放大橙色圆圈区域(不是很大,只是为了显示计算出焦点的位置)。正如您在下面看到的,红色圆圈正确计算了新焦点,但由于某种原因,绿色圆圈实际上是它放大/缩小的位置。

我正在使用以下代码将缩放坐标与实际的图像视图坐标映射
public boolean onScale(ScaleGestureDetector detector) {
        //update the current scale
    scaleFactor *= detector.getScaleFactor();
    scaleFactor = Math.max(ZOOM_LEVEL_4, Math.min(scaleFactor, ZOOM_LEVEL_0));
    //applying the scaleFactor to the focal point as determined in onScaleBegin
    transformMatrix.setScale(scaleFactor, scaleFactor, 
                  newFocalPoints[0], newFocalPoints[1]);
    //apply the matrix to the child
    child.transform(transformMatrix, newFocalPoints[0],  newFocalPoints[1],
                oldFocalPoints[0], oldFocalPoints[1]);
    return true;
}
@Override
public boolean onScaleBegin(ScaleGestureDetector detector){
    //when a new scaling process begins, get the current imageMatrix and 
    //map the points to account for the current zoom level
    //the initial points. based on screen location and current scroll pos
    float startX = detector.getFocusX() + getScrollX();
    float startY = detector.getFocusY() + getScrollY();
    oldFocalPoints = new float[]{startX, startY};
    //map oldFocalPoints to coordinates of the imageView based on current zoom
    Matrix inverseTransformMatrix = new Matrix();
    if(transformMatrix.invert(inverseTransformMatrix))
        inverseTransformMatrix.mapPoints(newFocalPoints, oldFocalPoints);
    return true;
}
上图中的绿点设置为{oldCoordinates[0], oldCoordinates[1]}用于调试目的,虽然它不是焦点,但它非常接近。所以看起来虽然我似乎正确地计算了新的焦点(红色圆圈),但它似乎并没有被正确应用。任何人都可以发现问题吗?提前致谢!