3
我有一個自定義的視圖,它在onDraw()的畫布上繪製一些位圖。該圖正在工作。看看代碼片段:Android:畫布不縮放
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.save();
if(appInitialized) {
hsSide.draw(canvas);
scaleA.draw(canvas);
scaleB.draw(canvas);
}
canvas.scale(mScaleFactor, mScaleFactor, pivotX, pivotY);
canvas.restore();
}
我已經實現了ScaleGestureListener,它在屏幕上應用了縮放縮放時縮放畫布。問題在於畫布不能縮放。如果我在if(appInitialized) {
之前放canvas.scale(mScaleFactor, mScaleFactor, pivotX, pivotY);
,它將縮放畫布,但在此之後,即hsSide.draw(canvas);
不縮放。它採用正常的規模。 這裏有繪畫方法:
hsDide.draw:
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.drawBitmap(mBitmap, canvas.getWidth()/2 - mBitmap.getWidth()/2, 0, null);
}
scaleA.draw:
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.drawBitmap(mBitmap, canvas.getWidth()/2 - mBitmap.getWidth()/2, canvas.getHeight()/2 - mBitmap.getHeight()/2, null);
}
scaleB.draw:
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.save();
mMatrix.setRotate(currentAngle, canvas.getWidth()/2, canvas.getHeight()/2);
canvas.setMatrix(mMatrix);
canvas.drawBitmap(mBitmap, canvas.getWidth()/2 - mBitmap.getWidth()/2, canvas.getHeight()/2 - mBitmap.getHeight()/2, null);
canvas.restore();
}
任何想法,我要去錯了... ???