2012-10-29 101 views
0

我有一個ImageView子類,應該在顯示圖像的底部顯示一個標誌。我有這個onDraw代碼在圖像上繪製圖標。它在ICS +上工作正常,但沒有降低。有誰知道這個的原因?Android Canvas繪圖不一致

@Override 
protected void onDraw(Canvas canvas) { 
    super.onDraw(canvas); 

    int canvasHeight = canvas.getHeight(); 
    int canvasWidth = canvas.getWidth(); 

    Drawable icon = getResources().getDrawable(R.id.icon); 

    int width = icon.getIntrinsicWidth(); 
    int height = iconcon.getIntrinsicHeight(); 

    int x = canvasWidth - width - PADDING; 
    int y = canvasHeight - height - PADDING; 

    icon.setBounds(x, y, canvasWidth - PADDING, canvasHeight - PADDING); 
    icon.draw(canvas); 
} 
+0

所以在較低版本,它會給出任何錯誤? –

回答

1

可能要忽略canvas.getWidth()canvas.getHeight()並使用onSizeChanged(int w, int h, int oldw, int oldh)而不是接收的值,因爲有時他們不匹配,並且canvas.getWidth()/getHeight()給出了奇怪的結果。