2011-10-21 50 views
1

我需要在屏幕上,在背景圖像上繪製一些矩形。對於這一點,我創建這個類:onDraw()被調用,但沒有顯示

public class MyImageView extends ImageView { 

    public MyImageView(Context context) { 
     super(context); 
    } 

    public MyImageView(Context context, AttributeSet attrs) { 
     super(context,attrs); 
    } 

    @Override 
    protected void onDraw(Canvas canvas) { 
     super.onDraw(canvas); 
     System.out.println("draw"); 
     Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.icon); 
     canvas.drawColor(Color.BLACK); 
     canvas.drawBitmap(background, 0, 0, null); 
    } 

} 

,並在活動的XML文件,我把:

<com.www.MyImageView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_marginLeft="150dip" 
     android:layout_marginTop="50dip"> 

logCat我得到的消息從onDraw()方法下來,但不會顯示任何內容。我的問題在哪裏?我錯過了什麼?

+1

變化WRAP_CONTENT到FILL_PARENT – ingsaurabh

+0

Thanks..that是問題:) – Gabrielle

+0

欣聞解決:)這個問題 – ingsaurabh

回答

0

只是嘗試canvas.drawBitmap(background, 0, 0, new Paint());

相關問題