How to implement dynamic measurements like sp and % in Jetpack Compose?

Viewed 151

Previously, there were units like % and sp and many more. But it seems there is only dp in Compose.

1 Answers

sp is used for text. This is still available:

Text("Cats are cool", textSize = 14.sp)

For %, you use weight. This example sets the width of the first column to 90% and the second to 10%:

Row(modifier = Modifier.fillMaxWidth) {
   Column(modifier = Modifier.weight(0.9f)) {

   }

   Column(modifier = Modifier.weight(0.1f)) {

   }
}
Related