Android: how to place a button at x, y position on top of the canvas

Can I place buttons in X, Y position on top of the canvas?

For example, on the first screen of my game, I would like to place buttons for "Play Now", "Instructions", etc. right on top of the canvas.

Right now, I am looking at the Touch positions on the canvas and comparing them with the various borders of X, Y. It works, but adding a button with a click listener is likely to be much more efficient.

+2
source share
1 answer

I found that if I use AbsoluteLayout and the XML button below, it works:

<Button  
  android:id="@+id/button"  
  android:layout_width="100px"  
  android:layout_height="wrap_content"  
  android:text="Button"  
  android:layout_x="50px"  
  android:layout_y="50px"  
/>
+1
source

All Articles