-1

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?

Joel
  • 4,732
  • 9
  • 39
  • 54
user2586488
  • 200
  • 1
  • 9

1 Answers1

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