Seems `Row` with `weight` inside `LazyRow` works u...
# compose
a
Seems
Row
with
weight
inside
LazyRow
works unexpected. The
Text
lacks available horizontal space.
Copy code
@Preview
@Composable
private fun Test() {
  LazyRow(modifier = Modifier.fillMaxWidth()) {
    item {
      Column {
        Row(modifier = Modifier.fillMaxWidth()) {
          Text(
            text = "Text",
            modifier = Modifier.weight(1f),
          )
          // some content...
        }
        // some content...
      }
    }
  }
}
1
c
How would you expect it to work? And what if you had multiple items?
a
I expect this result
c
and if there were multiple items in your row?
a
image.png
c
if you apply a weight to something in a column or a row, it'll attempt to occupy all the available space it can (sharing if other items have weight associated with them). However, in a LazyRow, or LazyColumn, there is no defined width (or height respectively) meaning such a calculation would be impossible.
you'll need to constrain the width of the Row you're setting the weight of a child in in some way
a
It is work right now. But in my expectations if i constrain by
fillMaxWidth
LazyRow and all child, i do the same. Thanks!
c
Nice! You could use
BoxWithConstraints
and use the scope inside the content lambda to obtain the
maxWidth
property which will reflect the size of the
BoxWithConstraints
composable (which could be different from the screen width). I'm not sure what your UI is going to eventually look like but you may not need a LazyRow (or the screen width stuff) if you're just creating the layout as it is above. Either way, keep going and good luck!
👍 1
z
Does fillMaxParentWidth work for you?
2
a
Does fillMaxParentWidth work for you?
Yes, this is exact what i need!
z
That will be MUCH better than BoxWithConstraints
c
That will be MUCH better than BoxWithConstraints
Oooo, noted, thanks Zach!
b
Was coming here to suggest the same thing @Zach Klippenstein (he/him) [MOD] 🤙