draw a single-touch motion path in android

2019-04-28 22:40发布

问题:

i am trying to make a drawing application.

i want to draw a single-touch motion path in android - like the way the Swype keyboard does it.

And consequently i want to store x-y coordinates of EACH of the pixels of the motion path into a data structure.

How can i use the MotionEvent pointers to do this?

回答1:

You probably don't have to store every pixel - just store a new one when certain parameters are met such as the pixel is further along or if the angle between one pixel and the next is greater than a certain threshold. From that you'll have a more compact poly line that will be easier to work with.



回答2:

You should look how to handle touch events here : http://developer.android.com/guide/topics/ui/ui-events.html

The example in the documentation of MotionEvent ( http://developer.android.com/reference/android/view/MotionEvent.html ) shows you how to get the coordinates of the touch event motion.

Then all you have to do is draw it (and maybe smooth it up a little)