@Composable
fun AnimatedVisibility01() {
var visible by remember { mutableStateOf(true) }
Column(horizontalAlignment = Alignment.Start) {
Button(onClick = { visible = !visible }) {
Text(text = if (visible) "Hide" else "Show")
}
Spacer(modifier = Modifier.height(20.dp))
AnimatedVisibility(visible = visible,
enter = fadeIn()+ expandVertically(),
exit = fadeOut() + shrinkVertically()
) {
Box(
modifier = Modifier
.size(1000.dp)
.background(Color.Blue),
contentAlignment = Alignment.Center
) {
Text(text = "Hello", color = Color.White)
}
}
}
}
12-27
1803
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-14
1152
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)