简体   繁体   English

在 Jetpack Compose 中为 Icon 使用 LottieAnimation

[英]Use LottieAnimation in Jetpack Compose for Icon

Is there any way to use a JSON animation file using LottieAnimation in Jetpack Compose for an interactive element such as a to-do list's checkmark so that it animates when clicked?有没有什么方法可以在 Jetpack Compose 中使用 LottieAnimation 将 JSON animation 文件用于交互式元素,例如待办事项列表的复选标记,以便在单击时设置动画?

I currently have a Row with Icon and a Column that further contains title and subtitle.我目前有一个带有图标的行和一个进一步包含标题和副标题的列。 I want this Icon to have a Lottie Animation.我希望这个图标有一个 Lottie Animation。

You can use theLottieAnimation composable.您可以使用LottieAnimation可组合项。

Something like:就像是:

var isPlaying by remember { mutableStateOf(false) }

val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.heart))
val progress by animateLottieCompositionAsState(
    composition,
    isPlaying = isPlaying,
)

Row(verticalAlignment = Alignment.CenterVertically) {
    LottieAnimation(
        composition = composition,
        progress = { progress },
        modifier = Modifier.clickable{ isPlaying = !isPlaying }
    )

    Text("Title", )
}

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM