Android drawing a line to follow your finger

后端 未结 6 1699
佛祖请我去吃肉
佛祖请我去吃肉 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:33

    A touch event is associated with a list of pointer counts retrievable like the following:

         int p = event.getPointerCount();
    

    iterating over these and drawing points can cause a continuous line to appear

    if (event.getAction() == MotionEvent.ACTION_MOVE
        || event.getAction() == MotionEvent.ACTION_DOWN) {
    
      int p = event.getPointerCount();
         for (int i = 0; i < p; i++) { 
           c.drawPoint(event.getX(i), event.getY(i), paint);
         }
    }
    

    Assuming paint is already set and c is the canvas, which may need to be locked (Eg- in a multithread application), prior to drawing on it.

提交回复
热议问题