views:

37

answers:

1

I am a beginner android developer and I am trying to have a button display on top of the bitmaps I am outputting.

Here is what I have:

my activity sets this:

setContentView(new FrameView(this));

FrameView is a class that extends View:

public FrameView(Context context) {
super(context);
    setFocusable(false);

Inside FrameView I have

@Override protected void onDraw(Canvas canvas){
...
canvas.drawBitmap(image1.getBitmap(), 0, 0, null);
...
}

main.xml is FrameLayout that I stuck a button on top of, that's it.

I guess my question is, how do I insert something into the main.xml as a "canvas" in order to paste my bitmaps to, but still have the button always on top regardless of how many bitmaps i draw?

+1  A: 

Use a RelativeLayout. Put your "canvas" as the first child, sized and positioned as you see fit. Put your button as the second child, sized and positioned as you see fit. Your button will "float" over your "canvas", because later children of a RelativeLayout are higher on the Z axis.

CommonsWare
Thanks, but my canvas is specified programmatically and my button is added in the design view, I can't seem to make my canvas available in the layout so how do I add it?
Hamid
@Hamid: Call `addView()` on whatever parent you want to use.
CommonsWare
Can you give some example? I tried this on my canvas and it isn't a valid call.
Hamid