如何在jetpack compose中使用浮动资源

问题描述 投票:0回答:2
android android-studio kotlin android-jetpack-compose android-jetpack
2个回答
0
投票

如果您的目标至少是 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
}

0
投票

我不得不恢复到旧的

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
}
© www.soinside.com 2019 - 2024. All rights reserved.