开发者

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

开发者 https://www.devze.com 2022-12-27 15:36 出处:网络
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, righ

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.


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"  
/>
0

精彩评论

暂无评论...
验证码 换一张
取 消