https://kotlinlang.org logo
#compose
Title
# compose
j

Julius Marozas

07/14/2020, 10:11 AM
I am a bit confused about drawing polylines on
Canvas
. I see that the
DrawScope.drawPath
function accepts
Path
as a parameter. However, I also found a quite convenient path builder function
PathData
which returns
List<PathNode>
. Can I somehow pass that list of path nodes to
DrawScope.drawPath
, i.e., construct a
Path
from
List<PathNode>
?
Okay, I found that I can do this:
Copy code
val path = Path().apply {
    moveTo(1f, 2f)
    lineTo(3f, 4f)
    lineTo(5f, 7f)
}

drawPath(path, Color.Red)
Now the issue is that the path has a fill (either with non-zero or even-odd
PathFillType
). How can I make a path without any fill?
I found a way to do this:
Copy code
drawCanvas { canvas, size ->
    canvas.drawPath(path, Paint().apply {
        color = Color.Red
        style = PaintingStyle.stroke
        strokeWidth = 3
    })
}
Note:
drawCanvas
is a function in the
DrawScope
, so it should be inside
Canvas
composable.
a

Andrey Kulikov

07/14/2020, 3:43 PM
there is a style param on drawPath where you can provide Stroke with your params instead of the default Fill
👍 1