开发者

Android Redrawing an image to new position when the screen is touched

I am trying to wri开发者_运维百科te a small android app that redraws an image everytime the screen is touched.

I expected the image to be redrawn to the new x,y coordinates provided by event.getX() and event.getY() when I override the onTouch(Event) method in an activity.

Can anyone help?


I presume, you'd be having the Bitmap object for the image.

You could call the onDraw() method from the onTouch() method, to draw the bitmap. Here's a code sample which shows the overridden onDraw() method:

protected void onDraw(Canvas canvas) 
      { 
         canvas.drawBitmap(imgBitmap, x, y, null);
      }

x,y are the new co-ordinates of the touch. imgBitmap is the Bitmap object for the image. You can update the instance variables x and y in the onTouch() method.

Hope this helps!!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜