2012-03-09 83 views
0

paint a drawCircle是否可以用圖像而不是顏色?如果是這樣,怎麼樣?如果不是,我有沒有辦法讓它看起來像?謝謝。drawCircle繪製位圖?

回答

1

您可以在您的Canvas上以所需的座標繪製多個圖像,就像您可以繪製圓圈一樣。正確使用setBounds方法來指定您希望繪製圖像的確切座標。以下是一個示例代碼:

public class MyDrawableView extends View { 
private Drawable mD1; 
private Drawable mD2; 

public MyDrawableView(Context context) { 
    super(context); 

    Resources res = context.getResources(); 
    mD1 = res.getDrawable(R.drawable.image1); 
    //Set image1 bounds using : mD1.setBounds(x, y, x + width, y + height); 

    mD2 = res.getDrawable(R.drawable.image2); 
    //Set image2 bounds using : mD2.setBounds(a, b, a + width, b + height); 
} 

protected void onDraw(Canvas canvas) { 
    mD1.draw(canvas); 
    mD2.draw(canvas); 
} 
}