开发者

How to draw a bitmap in FRONT of a layout in OnDraw

开发者 https://www.devze.com 2023-01-07 15:41 出处:网络
I have a layout that I have defined in an xml file which contains a number of ImageView\'s, RelativeLayout\'s, etc.

I have a layout that I have defined in an xml file which contains a number of ImageView's, RelativeLayout's, etc.

In OnCreate() I have the following code

public void开发者_StackOverflow社区 onCreate(Bundle savedInstanceState)
{
    super.onCreate( savedInstanceState );
    setContentView( R.layout.main );

In my override for the view, I have the following code

 class MainView extends View
 {
  .
  @Override
  protected void onDraw(android.graphics.Canvas canvas) 
  {
      .
      .
     canvas.drawBitmap( Bitmap, x, y, null );
  }

The x and y are calculated to coincide with one of my ImageViews ( I have verified that they are correct and the bitmap is valid ), my problem is that the bitmap is always drawn behind the ImageView. That is it is obscured by it. Is there any way to force the bitmap to draw in front of the ImageView?


why do you have an ImageView if you are going to draw the bitmap?

The view is always going to be in front. the image view sites on top of your activity, and you are drawing on your activity.

You can set the image src of the image view, or remove the image view and just draw to the canvas.


Reading the documentation carefully, I found

OnDraw

implement this to do your drawing.

Parameters

canvas the canvas on which the background will be drawn

which explains why the layout is in front of the bitmap

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号