tags:

views:

272

answers:

1

Hello,

I'm a bit stumped here, I'm trying to make it so an image (already in the drawable folder) gets created everytime you touch the screen and removed when the finger is lifted. I have the touch part coded already, overriding the onTouch method with a couple switch cases that handle each type of action (down, up, move, etc). But I can't for the life of me figure out how to make the image appear and then disappear with the coordinates (matrix?) of where the finger is.

Any help would be greatly appreciated!

A: 

You could use an object of the ImageView class to draw the image.

Get the co-ordinates of the touch event using the MotionEvent.getX(), MotionEvent.getY() or MotionEvent.getRawX(), MotionEvent.getRawY() functions (use the appropriate one depending on the kind of layout you are using, linear/relative). Use these co-ordinates as your ImageView object's left and top margins respectively.

Regrds, Anirudh.

aniait
I would add that using a FrameLayout may be beneficial in this scenario. get a reference to your layout view, and there should be a method on it similar to addView(), you could then call something like removeView() to remove the image when the touch is ended.
darren
Thanks! This was basically what I did, I was just having a but of trouble making the imageview's overlap. I was using LinearLayout, that was my problem.
dagonal