如何在jetpack compose中设计多圆形进度条?

Sal*_*eed 5 android android-progressbar progress-bar android-jetpack-compose

我正在尝试使用 jetpack compose 设计一个显示多个进度的进度条,但我没有找到任何库或帮助材料。我只能设计一个进度条,但我需要设计像

这个图片

Gab*_*tti 7

CircularProgressIndicator只需在 a 内使用多个Box

Box(contentAlignment = Alignment.Center) {
    CircularProgressIndicator(
        progress = 0.45f,
        color = Red,
        modifier = Modifier.then(Modifier.size(60.dp)))
    CircularProgressIndicator(
        progress = 0.55f,
        color = Green,
        modifier = Modifier.then(Modifier.size(80.dp)))
    CircularProgressIndicator(
        progress = 0.75f,
        color = Blue,
        modifier = Modifier.then(Modifier.size(100.dp)))
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

如果您还想绘制从 M21.4.0-alpha04和 M3开始的圆形轨迹1.1.0-alpha04,您可以使用以下trackColor 参数:

CircularProgressIndicator(
    //...
    trackColor = LightGray
)
Run Code Online (Sandbox Code Playgroud)

在此版本之前,如果您还想绘制圆形轨道,您可以使用Canvas+构建自定义可组合项CircularProgressIndicator
就像是:

   val stroke = with(LocalDensity.current) {
    Stroke(width = ProgressIndicatorDefaults.StrokeWidth.toPx(), cap = StrokeCap.Butt)
   }

    Canvas(modifier = Modifier.size(60.dp)){
        val diameterOffset = stroke.width / 2
        drawCircle(
            radius = size.minDimension / 2.0f-diameterOffset,
            color= LightGray,style = stroke)
    }
    CircularProgressIndicator(
        progress = 0.45f,
        color = Red,
        modifier = Modifier.then(Modifier.size(60.dp)))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述