开发者

Android: Dynamically placing buttons on a canvas

开发者 https://www.devze.com 2023-03-24 12:09 出处:网络
Thanks in advance for your assistance. I\'d like to know if it is possible for me to dynamically create a button and place it on top of a canvas given an x, y for button po开发者_StackOverflow中文版s

Thanks in advance for your assistance.

I'd like to know if it is possible for me to dynamically create a button and place it on top of a canvas given an x, y for button po开发者_StackOverflow中文版sition.

I have an image that's 2,000px by 1600 px or so, I have the ability to scroll around this image. I would like to place a button at say (100, 100)px with a pivot in the center of the button (say it's 50x50px) from within the activity.

The solution needs to be density and resolution independent... Any thoughts?

Thanks again!!


Placing a android.widget.Button inside a canvas probably will not work(with all buttons events etc working). As android.widget.Button is not a "canvas object". Placing a android.widget.Button on Top of a canvas will work (but then you don't need the canvas at all). Placing and android.widget object to a layout at a obsolete position cannot be done directly. You can only place ,for eg., the object at top-left position and then increase the margins do the android.widget will distance the anchor position.

If you want to play with canvas and positions directly create sprites. I would recommend a game engine for that thought like andengine.

0

精彩评论

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