設置縮放到指定的規模。圖像將圍繞點 (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