我需要在屏幕上的背景图像上绘制一些矩形。为此,我创建了这个类:
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()
方法中获取消息但没有显示任何内容。我的问题在哪里?我想念什么?