设置缩放到指定的规模。图像将围绕点 (focusX,focusY)为中心。这些浮标范围从0到1并且表示焦点 从视图的左侧和顶部的馏分。例如,左上 角的图像将是(0,0)。而右下角将是(1,1)。
public void setZoom(float scale, float focusX, float focusY, ScaleType scaleType) {
/*setZoom can be called before the image is on the screen, but at this point,
image and view sizes have not yet been calculated in onMeasure. Thus, we should
delay calling setZoom until the view has been measured.*/
if (!onDrawReady) {
delayedZoomVariables = new ZoomVariables(scale, focusX, focusY, scaleType);
return;
}
if (scaleType != mScaleType) {
setScaleType(scaleType);
}
resetZoom();
scaleImage(scale, viewWidth/2, viewHeight/2, true);
matrix.getValues(m);
m[Matrix.MTRANS_X] = -((focusX * getImageWidth()) - (viewWidth * 0.5f));
m[Matrix.MTRANS_Y] = -((focusY * getImageHeight()) - (viewHeight * 0.5f));
matrix.setValues(m);
fixTrans();
setImageMatrix(matrix);
}
希望这会有所帮助。快乐的编码。
'focalX'和'focalY'是从您的视图的左上角 – pskink
@pskink相对偏移我检查了这一点,但我原来的XY位置是远离视图的左上角它缩小了一个角。 – Kuls
如果你通过0,0的缩放是围绕你的意见左上角,如果你通过getWidth()/ 2,getHeight()/ 2缩放是围绕你的视图的中心等完成 – pskink