0

他の要素を持つ RelativeLayout の上にある動的な位置に画像を描画しようとしています。View を拡張してこのビューを RelativeLayout に追加するクラスを作成しようとしましたが、画面に表示されるのは画像だけです。RelativeLayout の他の要素は表示されません。

これはビュークラスです

@Override
protected void onDraw (Canvas canvas) {

    super.onDraw(canvas);
    Bitmap myBitmap = BitmapFactory.decodeResource(getResources(),    R.drawable.ic_launcher);
    canvas.drawColor(Color.BLACK);
    canvas.drawBitmap(myBitmap, 50,50, null);   
}

これはアクティビティの onCreate にあります

    mainLayout = (RelativeLayout)findViewById(R.id.main_tutorial_layout);
    mainLayout.addView( new DrawAnimationTutotial(getApplicationContext()));
    mainLayout.invalidate();
4

1 に答える 1

1

ImageView を使用しないのはなぜですか?

mainLayout = (RelativeLayout) findViewById(R.id.main_tutorial_layout);
ImageView image = new ImageView(this);
image.setImageDrawable(getResources().getDrawable(R.drawable.ic_launcher));

RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(50, 50);
layoutParams.leftMargin = xValue; 
layoutParams.topMargin = yValue;
image.setLayoutParams(layoutParams);
mainLayout.addView(image);
于 2012-07-15T04:32:55.690 に答える