gpt4 book ai didi

android - 每当我单击按钮/JetPack/Kotlin 时,在可组合函数中推送动画以重新开始

转载 作者:行者123 更新时间:2023-12-05 02:26:01 24 4
gpt4 key购买 nike

**每次用户单击按钮时,我想在框中显示不同的图标,并且过渡应该从其初始状态重新开始**

fun card(iconColor: Color){
val animateShape = remember { Animatable(50f) }
Card(
modifier = Modifier
.size(100.dp)
.padding(5.dp)
.border(width = Dp(animateShape.value), White, shape = CircleShape),
shape = CircleShape,
elevation = 5.dp,
backgroundColor = BlueGrey,
) {
Icon(
imageVector = Icons.Default.DoneAll,
contentDescription = null,
tint = iconColor,
modifier = Modifier
.padding(12.dp)

)
}
LaunchedEffect(iconColor) {
animateShape.animateTo(
targetValue = 2f,
animationSpec = repeatable(
animation = tween(
durationMillis = 3000,
easing = LinearEasing,
delayMillis = 500
),
iterations = 1
)
)
}
}```

最佳答案

我不太确定,但你在寻找这样的东西吗?每次点击它都会用 scaleIn/scaleOut 动画更改 Icon

@OptIn(ExperimentalAnimationApi::class)
@Composable
fun SwitchIconOnClick() {

var iconState by remember { mutableStateOf("State_1") }

AnimatedContent(
targetState = iconState,
contentAlignment = Alignment.Center,
transitionSpec = {
scaleIn(animationSpec = tween(durationMillis = 200)) with
scaleOut(animationSpec = tween(durationMillis = 200))
}
) { state ->

Box(
modifier = Modifier
.clip(CircleShape)
.size(50.dp)
.clickable {
when (state) {
"State_1" -> {
iconState = "State_2"
}
"State_2" -> {
iconState = "State_3"
}
"State_3" -> {
iconState = "State_1"
}
}
},
contentAlignment = Alignment.Center
) {
Icon(imageVector = when (state) {
"State_1" -> {
Icons.Rounded.NotificationAdd
}
"State_2" -> {
Icons.Rounded.ClosedCaption
}
"State_3" -> {
Icons.Rounded.Delete
}
else -> {
Icons.Rounded.DataArray
}
},
contentDescription = null
)
}
}
}

enter image description here

关于android - 每当我单击按钮/JetPack/Kotlin 时,在可组合函数中推送动画以重新开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74080089/

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