Android: how to place a button at an x,y position over top of Canvas

13,887

I found that if I use an AbsoluteLayout and the button XML 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"  
/>
Share:
13,887
Ben Mc
Author by

Ben Mc

Updated on June 05, 2022

Comments

  • Ben Mc
    Ben Mc almost 2 years

    Is it possible to place buttons at an X,Y position over the top of a Canvas?

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

    Right now, I'm looking at Touch locations on the Canvas and comparing them to various X,Y bounds. It works, but adding a button with a click listener would probably be much more efficient.

  • Christopher Orr
    Christopher Orr about 14 years
    If you're going to use absolute positioning, make sure to test it on all screen density types and orientations.