can you make an image button move in the same was as a bitmap in android

荒凉一梦 提交于 2019-12-25 02:13:19

问题


for the code I have a little android guy walk accross the screen, however this is using a bitmap how could I change it so it is an image button so I can click him and make it do somthing he is the code I have used for the bit map moving.

canvas.drawBitmap(AndroidDude, AndroidDudeChangingX, (canvas.getHeight()/2 - (AndroidDude.getHeight()/2)), null);
            if (AndroidDudeChangingX < canvas.getWidth() - 280)
            {
                AndroidDudeChangingX += 10;
            }
            else 
            {
                AndroidDudeChangingX = 0;
            }

回答1:


You don't need an imagebutton for that. Just get the Rect where your bitmap is located in the screen and implement the ontouch event of your activity. If the touch event happened inside of the Rect of your bitmap, you should handle the event properly.



来源:https://stackoverflow.com/questions/10471881/can-you-make-an-image-button-move-in-the-same-was-as-a-bitmap-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!