android - 如何在 Jetpack Compose 中像下面的布局一样实现波纹或波浪或雷达加载

标签 android android-studio kotlin android-jetpack-compose

如何在 Jetpack Compose 中添加波纹加载或波浪加载

enter image description here

最佳答案

您可以使用 Animation 检查下面的 Ripple Animation 代码 enter image description here

@Composable
fun RippleLoadingAnimation(
circleColor: Color = Color.Magenta,
animationDelay: Int = 1500
) {

// 3 circles
val circles = listOf(
    remember {
        Animatable(initialValue = 0f)
    },
    remember {
        Animatable(initialValue = 0f)
    },
    remember {
        Animatable(initialValue = 0f)
    }
)

circles.forEachIndexed { index, animatable ->
    LaunchedEffect(Unit) {
        // Use coroutine delay to sync animations
        // divide the animation delay by number of circles
        delay(timeMillis = (animationDelay / 3L) * (index + 1))

        animatable.animateTo(
            targetValue = 1f,
            animationSpec = infiniteRepeatable(
                animation = tween(
                    durationMillis = animationDelay,
                    easing = LinearEasing
                ),
                repeatMode = RepeatMode.Restart
            )
        )
    }
}

// outer circle
Box(
    modifier = Modifier
        .size(size = 200.dp)
        .background(color = Color.Transparent)
) {
    // animating circles
    circles.forEachIndexed { index, animatable ->
        Box(
            modifier = Modifier
                .scale(scale = animatable.value)
                .size(size = 200.dp)
                .clip(shape = CircleShape)
                .background(
                    color = circleColor
                        .copy(alpha = (1 - animatable.value))
                )
        ) {
        }
    }
}
}

关于android - 如何在 Jetpack Compose 中像下面的布局一样实现波纹或波浪或雷达加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74026059/

相关文章:

java - 通知未在指定时间显示

android - 在我的三星 Galaxy S10+ 上通过 IntelliJ/Android SDK 调试 Android 应用程序结果为 "Error while Installing APKs"

android - 如何在 Kotlin 中使用 Realm 的 in 方法

android - 将 AS 更新到 1.0 后,项目中出现 "method ID not in [0, 0xffff]: 65536"错误

安卓 : Layout with Rounded drop shadow

java - 如何从 Android 应用程序发送 ESC 命令?

android - 如何在android中覆盖双击电源按钮或音量按钮?

java - Android studio - 我很难弄清楚为什么 onTouchtEvent 无法识别手指移动。有什么建议么?

kotlin - 空指针异常与 map 一起使用(Kotlin)

kotlin - 如何初始化lateinit变量?