在 Jetpack Compose 中绘制动画圆圈

Animating circle drawing in Jetpack compose

我正尝试在 Canvas 上使用 drawCircle 制作圆图动画,如下所示:

 drawCircle(
     color = Color.Black,
     radius = 200f * animatableCircle.value,
     center = Offset(size.width / 4, size.height / 4),
     style = Stroke(2f)
)

它看起来不像是正在绘制圆圈,而是圆圈开始从中心开始缩放。是否可以实现如图中类似CircularProgressIndicator的沿半径画圆的效果?

使用drawArc如下,

 drawArc(
     color = Color.Black,
     startAngle = 0f,
     sweepAngle = 360f * animatableCircle.value,
     useCenter = false,
     topLeft = Offset(size.width / 4, size.height / 4),
     size = Size(CIRCLE_RADIUS * 2 ,
                 CIRCLE_RADIUS * 2),
     style = Stroke(2.0f))

只是为了完成 发布的代码:(+1)

    val radius = 200f
    val animateFloat = remember { Animatable(0f) }
    LaunchedEffect(animateFloat) {
        animateFloat.animateTo(
            targetValue = 1f,
            animationSpec = tween(durationMillis = 3000, easing = LinearEasing))
    }

   Canvas(modifier = Modifier.fillMaxSize()){
       drawArc(
           color = Color.Black,
           startAngle = 0f,
           sweepAngle = 360f * animateFloat.value,
           useCenter = false,
           topLeft = Offset(size.width / 4, size.height / 4),
           size = Size(radius * 2 ,
               radius * 2),
           style = Stroke(2.0f))
   }