【问题标题】:Animating circle drawing in Jetpack compose在 Jetpack compose 中绘制动画圆
【发布时间】:2021-04-13 18:30:25
【问题描述】:

我正在尝试在Canvas 上使用drawCircle 为圆形绘图设置动画,如下所示:

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

看起来不像是在画圆,而是圆从中心开始按比例缩放。如图所示,是否可以实现类似于CircularProgressIndicator 的半径的画圆效果?

【问题讨论】:

标签: android kotlin android-jetpack-compose


【解决方案1】:

只是为了完成@Varsha Kulkarni发布的代码:(+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))
   }

【讨论】:

  • 非常感谢!这肯定是完整的答案:)
【解决方案2】:

如下使用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))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多