1

I want to draw line on android canvas like this: enter image description here That is, I want to draw a white colored line & shadow effect of different color. I have tried shadow layers but getting different output. Here's my code:

private void drawLine(float lx, float ly, float x, float y,  Paint paint) {


    shadowPaint.setMaskFilter(new BlurMaskFilter(12f, BlurMaskFilter.Blur.NORMAL));

    shadowPaint.setColor(Color.RED);
    shadowPaint.setStrokeWidth(lineWidth*2);
    mPaintCanvas.drawLine(lx,ly,x,y,shadowPaint);
    paint.setColor(Color.WHITE);
    mPaintCanvas.drawLine(lx,ly,x,y,paint);
    
    last_x = x;
    last_y = y;
    postInvalidate();
}

My output: enter image description here Please give me a idea how to achieve this.

  • 1
    What you are looking for is [Canvas.drawPath] (https://developer.android.com/reference/android/graphics/Canvas#drawPath(android.graphics.Path,%20android.graphics.Paint)) . I'm from mobile so I cannot give you a full answer – Jameido May 26 '21 at 09:58
  • Thanks but I failed to do the job that I want even using path. Can you please give full answer when you are free enough? Note: I need to keep drawing this kind of line while touching canvas that is drawLine method is call on Action.MOVE. – Nafia Mahjabin May 26 '21 at 10:43
  • 2
    Take a look at [this](https://stackoverflow.com/a/16650524/5251245) – Jameido May 26 '21 at 12:53

0 Answers0