I am working on an android application that does drawing with a Canvas object. Suppose a circle gets drawn on the Canvas. Is there a way I can let the user drag and drop that circle to a different location on the Canvas?
Asked
Active
Viewed 108 times
-1
-
Can you show us what you have done so far. – Dulanga Jul 18 '13 at 17:34
-
i have added lines and circles on the canvas.i just need a way to move those lines.Is it possible in android – user2586488 Jul 18 '13 at 17:38
-
you could use 'canvas.translate()' but you need to call 'invalidate()' method first to change their positions. – Dulanga Jul 18 '13 at 17:46
-
Would it work if there are multiple lines on the canvas and i want to move only one of the lines – user2586488 Jul 18 '13 at 17:52
-
Hi, please let me know what kind of changes you want me to make to this question.I am not asking for code,I just want to know if it is possible to drag and drop elemnts drawn on a canvas – user2586488 Jul 19 '13 at 07:48
-
Hi, can somebody open this question – user2586488 Jul 19 '13 at 10:14
1 Answers
1
If I understand your question then I think your approach (the way your thinking about it) is wrong. When the user draws something, say a line, then you need to objectize that. That is you would create an instance of an object that knows the start coordinate and the end coordinate, and maybe the colour etc. The user would then do some gesture to select what they would think of as a line but what your program knows as an object, move it, and then your program would re-draw the canvas.

tallen
- 677
- 6
- 17
-
Hi, thanks for the reply.To use this approach ,I will first have to know when the user has touched the line or some other element drawn on the screen.Is that possible in android – user2586488 Jul 18 '13 at 18:08
-
yup, have a look at this, it might help...http://stackoverflow.com/questions/5743328/image-in-canvas-with-touch-events – tallen Jul 18 '13 at 18:11
-
actually, the above answers the problem of touch events. So you'll have the user do, something, to sorta put the canvass in "edit" mode and then when they touch, you spin through the "line" objects and figure out which line is closest to the place where they touched, then when they lift up, you change the start and end coords in that object and redraw. It's not as straight forward as you might have supposed :-) – tallen Jul 18 '13 at 18:15
-
also, I'm not saying this is *the* way to do this, it is a way to do it. The only way I can think of at the moment. – tallen Jul 18 '13 at 18:16