23

I have a Row with max width, I want to place a Icon at start then a text and then another Icon at end. I have specific sizes of icon and I want the Text to fill up the remaining space.

Row(
   Modifier
   .fillMaxWidth()
   .height(30.dp)
){
  Icon(Modifier.size(20.dp))

  Text() // Fill this with remaining space available

  Icon(Modifier.size(20.dp))
}

If I do fillMaxWidth in text then Icons goes out of the view.

How to do that?

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
DelusionaL
  • 745
  • 2
  • 6
  • 15

1 Answers1

59

You can apply Modifier.weight(1f) to the Text composable.

Something like:

Row(
    Modifier
        .fillMaxWidth()
        .height(30.dp)
){
    Icon(Icons.Filled.Add,"", Modifier.size(20.dp))

    Text("Text",Modifier.weight(1f)) // Fill this with remaining space available

    Icon(Icons.Filled.Add,"", Modifier.size(20.dp))
}

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841