android Jetpack组合-一个圆圈, Flink 3秒,停止3秒,可重复

7y4bm7vi  于 2023-03-21  发布在  Android
关注(0)|答案(1)|浏览(109)

到目前为止,我有这个-我如何使它 Flink 3秒钟停止3秒钟。然后重复这个直到组合被处理。

@Composable
fun FlashingLight ( size: Dp , color: Color){
    val infiniteTransition = rememberInfiniteTransition()

    val lightFlashing by infiniteTransition.animateFloat(
        initialValue = 0.0f,
        targetValue = 1.0f,
        animationSpec = infiniteRepeatable(
            animation = tween(
                durationMillis = 500,
                delayMillis = 10,
                easing = LinearEasing),
            repeatMode = RepeatMode.Reverse
        )
    )

    Canvas(modifier = Modifier
        .size(size),

        onDraw = {
            drawCircle(color = color.copy(alpha = lightFlashing))
        })
}

我试过了-不成功

LaunchedEffect(key1 = true) {
    repeat(3) {
    .........
    }
}

谢谢

unftdfkk

unftdfkk1#

在费力地阅读了文档之后-这很有效。

val lightFlashing by infiniteTransition.animateFloat(
    initialValue = 0.0f,
    targetValue = 1.0f,
    animationSpec = infiniteRepeatable(
        animation = keyframes {
            durationMillis = 6000
            0.0f at 0 with LinearOutSlowInEasing
            1.0f at 500 with LinearOutSlowInEasing
            0.0f at 1000 with LinearOutSlowInEasing
            1.0f at 1500 with LinearOutSlowInEasing
            0.0f at 2000 with LinearOutSlowInEasing
            1.0f at 2500 with LinearOutSlowInEasing
            0.0f at 3000 with LinearOutSlowInEasing
            0.0f at 6000 with LinearOutSlowInEasing
        },
        repeatMode = RepeatMode.Restart,
    )
)

相关问题