can you make an image button move in the same was

2019-08-17 18:46发布

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条回答
等我变得足够好
2楼-- · 2019-08-17 19:01

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.

查看更多
登录 后发表回答