Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose Fill remaining space in Row

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?

like image 631
DelusionaL Avatar asked May 23 '21 14:05

DelusionaL


People also ask

What is LazyColumn in jetpack compose?

A LazyColumn is a vertically scrolling list that only composes and lays out the currently visible items. It's similar to a Recyclerview in the classic Android View system.

What is Mutablestateof in jetpack compose?

If you want to change the state of TextField and also update the UI, you can use a MutableState . Compose observes any reads and writes to the MutableState object and triggers a recomposition to update the UI.

When to Use remember jetpack compose?

remember can be used to store both mutable and immutable objects. Note: remember stores objects in the Composition, and forgets the object when the composable that called remember is removed from the Composition.


1 Answers

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

like image 128
Gabriele Mariotti Avatar answered Oct 20 '22 00:10

Gabriele Mariotti