Reputation: 505
I am trying to draw a image at dynamic positions on top of a RelativeLayout that has other elements. I tried creating a class that extends View and add this view to the RelativeLayout but the image is only thing that is shown on the screen. The other elements in the RelativeLayout are not visible.
this is the view class
@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);
}
this is in the onCreate of the Activity
mainLayout = (RelativeLayout)findViewById(R.id.main_tutorial_layout);
mainLayout.addView( new DrawAnimationTutotial(getApplicationContext()));
mainLayout.invalidate();
Upvotes: 0
Views: 968
Reputation: 957
Why not use an 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);
Upvotes: 1