37

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?

1 Answer 1

86

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

Sign up to request clarification or add additional context in comments.

3 Comments

I have one more problem. i have decreased the height of TextField but the Placeholder text and input text are getting cropped. i.e. only 50% visible. how to solve it?
@DelusionaL Try to decrease the textsize
Then it's getting too small, only 8.sp is working which affects accessibility.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.