我在我的项目中使用了 compose AnimatedVisibility,
但是动画是我需要的缩写。
有相关的API吗?
最佳答案
这是取自 codelabs 的示例.您可以使用每个动画的 durationMillis 添加自己的动画规范,一个用于进入,一个用于退出:
AnimatedVisibility(
visible = shown,
enter = slideInVertically(
// Enters by sliding down from offset -fullHeight to 0.
initialOffsetY = { fullHeight -> -fullHeight },
animationSpec = tween(durationMillis = 150, easing = LinearOutSlowInEasing)
),
exit = slideOutVertically(
// Exits by sliding up from offset 0 to -fullHeight.
targetOffsetY = { fullHeight -> -fullHeight },
animationSpec = tween(durationMillis = 250, easing = FastOutLinearInEasing)
)
) {
Surface(
modifier = Modifier.fillMaxWidth(),
color = MaterialTheme.colors.secondary,
elevation = 4.dp
) {
Text(
text = stringResource(R.string.edit_message),
modifier = Modifier.padding(16.dp)
)
}
}
关于android - 如何在撰写中控制 AnimatedVisibility 的持续时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68752661/