views:

87

answers:

2

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 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?

A: 

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.

Ryan Conrad
A very good question, I tried using SetImageDrawable() but it was very costly, so I am trying to shortcut that by drawing the image in OnDraw()However I think I have answered my own question, the canvas in OnDraw is the canvas on which the background will be drawn according to the documentation. That would explain why the bitmap is being obscured but does not solve my problem unfortunatelyDo you have any suggestions for speeding up changing the ImaveView's src?
remove the image view, if you dont need it. if it is still to slow, maybe you want to look in to using a GLSurfaceView where you can use OpenGL to draw your images as textures. I have very little experience with it, but it is faster
Ryan Conrad
A: 

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