kotlin 在Jetpack合成中绘制圆动画

sczxawaw  于 2023-03-13  发布在  Kotlin
关注(0)|答案(2)|浏览(98)

我尝试在Canvas上使用drawCircle绘制圆形动画,如下所示:

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


看起来不像是在画圆,而是从圆心开始缩放,是否可以像CircularProgressIndicator那样,沿着半径方向画圆?

qhhrdooz

qhhrdooz1#

为了完成@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))
   }

jbose2ul

jbose2ul2#

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

相关问题