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!!
精彩评论