Ran*_*mar 7 android android-animation android-jetpack-compose
我尝试了 Jetpack Compose 中的动画。我在旋转动画中遇到问题。
看起来一切都很好。但不知道为什么它不起作用。
我的代码:
@Composable
private fun RotateAnimationContent() {
val isRotated = rememberSaveable { mutableStateOf(false) }
val rotationAngle by animateFloatAsState(
targetValue = if (isRotated.value) 360F else 0F,
animationSpec = tween(durationMillis = 1500,easing = FastOutLinearInEasing)
)
Column {
Box(modifier = Modifier.background(Color.Red).size(100.dp).rotate(rotationAngle))
Button(
onClick = { isRotated.value = !isRotated.value },
modifier = Modifier.padding(10.dp)
) {
Text(text = "Rotate Box")
}
}
}
Run Code Online (Sandbox Code Playgroud)
Put the .rotate(rotationAngle)
as the first modifier of the Box
. Before background and size.
Column {
Box(modifier = Modifier.rotate(rotationAngle).background(Color.Red).size(100.dp))
Button(
onClick = { isRotated.value = !isRotated.value },
modifier = Modifier.padding(10.dp)
) {
Text(text = "Rotate Box")
}
}
Run Code Online (Sandbox Code Playgroud)
Check this very detailed answer to better understand why the order of modifiers matters.
归档时间: |
|
查看次数: |
1722 次 |
最近记录: |