我需要更改缩放和移动图像视图的方式,以使用矩阵而不是调用canvas.scale(,,,,)
,但我无法弄清楚执行此操作的正确调用。
我ScaleListener
在侦听器类的onScale
方法中有这个
public boolean onScale(ScaleGestureDetector detector) {
...//determining zoom level and pivot points offset
child.zoom(scaleFactor, zoomCenter[0], zoomCenter[1]);
}
我在孩子ImageView的onDraw
方法:
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
canvas.scale(mScaleFactor, mScaleFactor, mPosX, mPosY);
...
//do all the drawing here
}
public void zoom(float scaleFactor, float zoomCenterX, float zoomCenterY) {
mScaleFactor = scaleFactor;
mPosX = zoomCenterX;
mPosY = zoomCenterY;
//redraw and remeasure the mapview after zooming in
invalidate();
}
我希望在方法中有这样的东西onScale
:
public boolean onScale(ScaleGestureDetector detector) {
...//calculating scale and offsets
Matrix m = child.getImageMatrix();
m.reset();
m.postScale(scaleFactor, scaleFactor);
m.postTranslate(zoomCenter[0], zoomCenter[1]);
child.setScaleType(ScaleType.MATRIX);
child.setImageMatrix(m);
child.invalidate();
return true;
}
但这似乎没有做任何事情......我在这里错过了什么吗?我尝试child.getMatrix()
改用,但是通过 IllegalStateException 说不能修改矩阵。任何帮助都会很棒!