我想在畫布上繪製多個圖像並顯示它,但我只是不知道如何。在Android上的畫布上繪製多個圖像
這裏是我的代碼:
public class CustomDrawableView extends View {
private Drawable mDrawable;
private Drawable mD2;
public CustomDrawableView(Context context) {
super(context);
int x = 40;
int y = 100;
int width = 20;
int height = 10;
Resources res = context.getResources();
mDrawable = res.getDrawable(R.drawable.main);
mDrawable.setBounds(x, y, x + width, y + height);
mD2 = res.getDrawable(R.drawable.virus);
mD2.setBounds(x+50,y-70,width+10,height+5);
}
protected void onDraw(Canvas canvas) {
mDrawable.draw(canvas);
Canvas canvas2 = new Canvas();
mD2.draw(canvas2);
}
}
您不需要創建畫布的新實例,只需執行 md2.draw(canvas)。 – user710502 2012-02-10 03:15:02
我嘗試過......但它沒有奏效。這就是爲什麼我想可能有2個畫布會起作用... – 2012-02-10 03:17:49
當你只繪製mDrawable,然後只繪製md2時,會發生什麼? – user710502 2012-02-10 03:26:13