我需要改變我縮放和移動我的imageview到使用矩陣,而不是調用canvas.scale(,,,,)
,但我無法弄清楚正確的呼叫來做到這一點。使用ImageView變換矩陣,而不是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表示矩陣不能修改。任何幫助將是偉大的!
謝謝!你節省了我幾個小時的時間! – Tomasz