Android: how to place a button at an x,y position

2019-04-13 07:20发布

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.

1条回答
贪生不怕死
2楼-- · 2019-04-13 08:11

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"  
/>
查看更多
登录 后发表回答