android - adding a button to activity WITHOUT any layout -


The problem is well that I have been using a type of SurfaceView in my activity, and I Want to add a button.

My questions are:

1) How do I create an example without a button of search? ViewById (...)? (Because I do not have layout due to surface view) ...

2) And how do I attract this button to the canvas?

Or are you suggesting something else?

I care that there will be a button on my screen and I can apply something like OnClickListener (...) ....

thanks all before !!!

After

You draw your buttons on the canvas (which is possible), they will not be able to click here. Do you really want to:

  • Wrap your SurfaceView into a frame layout - if you also add other views to the same layout, they will appear above the SurfaceView;
  • Add a relative layout in the frame layout mentioned above (so you can create the position of the button and potential other scenes - you can only set the margins if you have only the button).

    Like:

       & Lt; RelativeLayout Android: layout_width = "fill_parent" android: layout_height = "fill_parent" & gt; & Lt; Android: layout_centerHorizontal = "true" Android: layout_centerVertical = "true" Android: onClick = "whatever" android: id = "@ + id / restartButton" Android: layout_width = "wrap_content" android: layout_height = "wrap_content" : Text = "Look, I float above ground floor!" / & Gt; & Lt; / RelativeLayout & gt; & Lt; / FrameLayout & gt;    

Comments