如果您的目标至少是 API 29,则可以使用:
val floatValue = LocalContext.current.resources.getFloat(R.dimen.loading_circle_target)
@Composable
fun LoadingCircle() {
val currentRotation by transition.animateValue(
0F,
targetValue = floatValue,
// .. more code in here
)
// more code in here
}
我不得不恢复到旧的
is_phone
bool,因为 booleanResource()
支持较旧的 API 级别。所以有
<resources>
<bool name="is_phone">false</bool>
</resources>
在 values-sw600dp 文件夹中并将其设置为正常值文件夹中的
true
。然后就可以像这样使用了
@Composable
fun LoadingCircle() {
val currentRotation by transition.animateValue(
0F,
targetValue = if (booleanResource(id = R.bool.is_phone)) 360f else 180f
)
// more code in here
}