简体   繁体   中英

Jetpack Compose: How to draw a path like this

I wanted to show two points in this way:

图片!

Is there some reference that I can look up?

Just use a Canvas and draw 2 circles and 1 line.

Canvas(Modifier.fillMaxSize()){

    val radius = 64f //radius of circles
    val strokeWidth = 20f 
    val lineHeight = 300f
    val centerFirstCircle = Offset(100f, 100f)

    drawCircle(
        color = Color.Red,
        radius = radius,
        center = centerFirstCircle,
        style = Stroke(width = strokeWidth)
    )

    //calculate the start and end of the vertical line
    val xLine = centerFirstCircle.x
    val yLine = centerFirstCircle.y + radius + strokeWidth/2

    drawLine(
        color = Red,
        start = Offset(xLine, yLine),
        end = Offset(xLine , yLine + lineHeight),
        strokeWidth = strokeWidth
    )

    //calculate the center of the second circle
    val centerSecondCircle = Offset( centerFirstCircle.x,
        centerFirstCircle.y + (radius*2) + lineHeight + (strokeWidth/2 *2) )

    drawCircle(
        color = Color.Red,
        radius = radius,
        center = centerSecondCircle,
        style = Stroke(width = strokeWidth)
    )
}

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM