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(), но ничего не отображается. Где моя проблема? Что мне не хватает?


person Gabrielle    schedule 21.10.2011    source источник
comment
Измените wrap_content на fill_parent   -  person ingsaurabh    schedule 21.10.2011
comment
Спасибо .. это была проблема :)   -  person Gabrielle    schedule 21.10.2011
comment
Рад слышать, что проблема решена :)   -  person ingsaurabh    schedule 21.10.2011


Ответы (1)


просто попробуй canvas.drawBitmap(background, 0, 0, new Paint());

person Huang    schedule 21.10.2011