ebe*_*lli 4 android kotlin android-jetpack android-jetpack-compose
将进入和退出过渡添加到 时AnimatedVisibility,如果可组合动画具有偏移修饰符,则过渡不可见:
AnimatedVisibility(
visible = visible,
enter = fadeIn(animationSpec = tween(1000)),
exit = fadeOut(animationSpec = tween(1000))
) {
Text(
text = "Hello, world!", modifier = Modifier
// This will make the transition not working
//.offset(100.dp, 0.dp)
)
}
Button(onClick = { visible = !visible }) {
Text("Click Me")
}
Run Code Online (Sandbox Code Playgroud)
这是没有偏移的动画:
这是带有偏移量的动画:
有办法让它发挥作用吗?
不要将偏移修饰符放在Text. 把它改为AnimatedVisibility:
AnimatedVisibility(
visible = visible,
enter = fadeIn(animationSpec = tween(1000)),
exit = fadeOut(animationSpec = tween(1000)),
modifier = Modifier.offset(100.dp, 0.dp)
) {
Text(text = "Hello, world!")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2555 次 |
| 最近记录: |