gpt4 book ai didi

android - 如何在 Jetpack Compose 中为 TextStyle 设置动画?

转载 作者:行者123 更新时间:2023-12-02 16:08:55 25 4
gpt4 key购买 nike

当某个 bool 变量为真时,我的一个可组合项中的文本被删除线。如何在重组时为 TextStyle 中的这种变化设置动画,以便该行淡入而不是突然出现和消失?

@Composable
fun MyComposable(
completed: Boolean
) {
val textStyle = TextStyle(textDecoration = if (completed) TextDecoration.LineThrough else null)

Text(
text = title,
color = textColor,
style = textStyle,
modifier = Modifier.align(Alignment.CenterVertically)
)

最佳答案

不确定是否存在为 TextStyle 设置动画的方法。
这不是一个很好的解决方案,只是一种解决方法:

Box() {
AnimatedVisibility(
visible = !completed,
enter = fadeIn(
animationSpec = tween(durationMillis = duration)
),
exit = fadeOut(
animationSpec = tween(durationMillis = duration)
)) {
Text(
text = title,
style = TextStyle(textDecoration=null)
)
}
AnimatedVisibility(
visible = completed,
enter = fadeIn(
animationSpec = tween(durationMillis = duration)
),
exit = fadeOut(
animationSpec = tween(durationMillis = duration)
)) {
Text(
text = title,
style = TextStyle(textDecoration = TextDecoration.LineThrough),
)
}
}

enter image description here

关于android - 如何在 Jetpack Compose 中为 TextStyle 设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68576828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com