开发者

Android SDK: Create image on touch

开发者 https://www.devze.com 2022-12-28 01:50 出处:网络
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 co

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!


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.

0

精彩评论

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