Android drawing a line to follow your finger

后端 未结 6 1700
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 01:27

What I want to do is to draw a line that will follow my finger. I\'ve created a custom view, and I have an onTouchEvent() that works.

I can draw a sta

6条回答
  •  情书的邮戳
    2020-12-13 01:36

    You're only tracking the up and down events. Track the ACTION_MOVE event too. Beware that it will track continuously, even if the person's finger isn't apparently moving. Your code should go something like this:

    ACTION_DOWN: Store position.

    ACTION_MOVE: If position is different from stored position then draw a line from stored position to current position, and update stored position to current.

    ACTION_UP: Stop.

    In the ACTION_MOVE bit, it might be a good idea to check if the position is at least 2 or 3 pixels away from the stored position. If you're going to store all of the plot points, so you can do something with the data later, then maybe increase that to 10 pixels so you don't end up with hundreds of points for a simple line.

提交回复
热议问题