`Modifier.fillMaxHeight()` is not working, can som...
# compose
m
Modifier.fillMaxHeight()
is not working, can some one explain me what I am doing wrong?
Copy code
Row(Modifier.padding(horizontal = 32.dp, vertical = 16.dp).background(Color.Red)) {
    Column(Modifier.fillMaxHeight().weight(1f).background(Color.Cyan)) {
        Row {
            Image(
                asset = imageResource(id = Drawables.mappin),
                Modifier.gravity(Alignment.CenterVertically)
            )
            Column(Modifier.padding(start = 16.dp)) {
                Text(
                    text = "Address", style = TextStyle(
                        color = Color.Black.copy(alpha = 0.7f),
                        fontSize = 20.sp
                    )
                )
                Text(
                    text = "House # 2, Road # 5, Green Road Dhanmondi, Dhaka, Bangladesh",
                    style = TextStyle(color = Color.Gray)
                )
            }
        }
        Row {
            Image(
                asset = imageResource(id = Drawables.clock),
                Modifier.gravity(Alignment.CenterVertically)
            )
            Column(Modifier.padding(start = 16.dp)) {
                Text(
                    text = "Daily Practice", style = TextStyle(
                        color = Color.Black.copy(alpha = 0.7f),
                        fontSize = 20.sp
                    )
                )
                Text(
                    text = "Monday - Friday Open till 7 Pm",
                    style = TextStyle(color = Color.Gray)
                )
            }
        }
    }
    Image(
        asset = imageResource(id = Drawables.map),
        modifier = Modifier.fillMaxHeight().weight(1f)
    )
}
z
What result are you expecting?
y
I'm guessing the equivalent of a
matchParentHeight
, a bit like the
matchParentSize
we have in a
StackScope
I've been looking for a way to make every children in a row match its parent height. Only answer I have to far is using constraint layout
m
@Zach Klippenstein (he/him) [MOD] I want to make the blue section match it's parent height
m
It should work if you do
Row(Modifier.padding(horizontal = 32.dp, vertical = 16.dp).size(IntrinsicSize.Max).background(Color.Red))
. This will premeasure the height of the
Row
and then when the
Column
does
fillMaxHeight
the height filled will be the premeasured one rather than the `Row`'s available height.
The alternative, sure, is to use
ConstraintLayout
. Even if the layout is expressed in a different way, it will do a similar premeasurement under the hood.
y
The
size(IntrinsicSize.MAX)
doesn't seem to exist (anymore?), use instead:
Copy code
preferredHeight(IntrinsicSize.Max)
Did the trick for me Thanks for the tip @Mihai Popa (Though it's marked as experimental layout api)
m
No problem! Yes, I meant
height
, which should exist as well as
preferredHeight
.
y
Actually it doesn't seem to exist for
height
, only
preferredHeight
m
Yes, I meant that we should add them 🙂
👍 1
467 Views