为什么动画无法正常工作?

问题描述 投票:0回答:1
我不知道为什么在制作动画时,按钮突然的转移会发生。我谦虚地要求帮助我。

这是我的动画组合:

@Composable fun AnimateWithFadingIn(modifier: Modifier = Modifier){ var isShowing by remember { mutableStateOf(false) } val iconOffset by animateDpAsState( targetValue = if (isShowing) 80.dp else (0).dp, label = "", animationSpec = tween(durationMillis = 1000) ) val rotationAngle by animateFloatAsState( targetValue = if (isShowing) 360f else 0f, animationSpec = tween(durationMillis = 1000) ) Column( modifier = modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center ) { Row { AnimatedVisibility( visible = isShowing, enter = slideInHorizontally(initialOffsetX = {it},animationSpec = tween(durationMillis = 1000)) + fadeIn(animationSpec = tween(durationMillis = 1000)), exit = slideOutHorizontally (targetOffsetX = {it/2},animationSpec = tween(durationMillis = 1000)) + fadeOut(animationSpec = tween(durationMillis = 1000)) ) { Text("Text is showing") } if (isShowing){ Spacer(modifier = Modifier.width(8.dp)) } IconButton(modifier = Modifier.size(40.dp).offset(x = iconOffset).rotate(degrees = rotationAngle), onClick = {isShowing = !isShowing}) { Icon(imageVector = Icons.Default.Clear, contentDescription = null) } } } }

基于这一点
trory将
android kotlin android-jetpack-compose android-jetpack jetpack-compose-animation
1个回答
0
投票
添加到IconOffset(如果可用,如果不尝试将其更改为

animateFloatAsState并将DP存储为float)

如果有效,我将更新答案,以解释为什么可以解决IT

	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.