@Composable
fun AnimateSizeAsState01() {
var visible by remember { mutableStateOf(true)
}
val scale by animateSizeAsState(targetValue = if (visible) Size(200.dp.value, 200.dp.value) else Size(0.dp.value, 0.dp.value),animationSpec =
tween(durationMillis = 2000)
)
Column(horizontalAlignment = Alignment.Start) {
Button(onClick = { visible = !visible }) {
Text(text = if (visible) "Hide" else "Show")
}
Spacer(modifier = Modifier.height(20.dp))
Box(
modifier = Modifier
.size(scale.width.dp,scale.height.dp)
.background(Color.Blue),
contentAlignment = Alignment.Center
) {
Text(text = "animateSizeAsState", color = Color.White)
}
}
}
04-29
1629
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-29
1014
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-14
707
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-15
1035
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)