1

I have float value 360F. I created a filed called float.xml inside res/values.

float.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="loading_circle_target" format="float" type="dimen">360</item>
</resources>

and use like this

@Composable
fun LoadingCircle() {
    val currentRotation by transition.animateValue(
        0F,
        targetValue = dimensionResource(id = R.dimen.loading_circle_target).value,
        // .. more code in here
    )
    // more code in here
}

I am getting error in here

android.content.res.Resources$NotFoundException: Resource ID #0x7f070346 type #0x4 is not valid                                                                                                        at android.content.res.Resources.getDimension(Resources.java:766)                                                                                                           
at androidx.compose.ui.res.PrimitiveResources_androidKt.dimensionResource(PrimitiveResources.android.kt:79)

UPDATE

I have minimum sdk is 21

Kotlin Learner
  • 3,995
  • 6
  • 47
  • 127

1 Answers1

1

if you're targetting at least API 29 you can use:

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
}
Lino
  • 5,084
  • 3
  • 21
  • 39