I try to achieve this layout but don't really know how:
currently it looks like this:
using this Code:
@Preview(widthDp = 150)
@Composable
fun Item() {
Card(shape = RoundedCornerShape(8.dp)) {
Row {
Box(Modifier.background(Color.Yellow).weight(1f)) {
SomeMoreContentWithUnknownHeight()
}
Box(Modifier.width(20.dp).height(IntrinsicSize.Max).background(Color.Green))
}
}
}
I tried to set the height of the second Box to IntrinsicSize.Max but that didn't change anything. I am currently running Jetpack Compose in Version 1.0.0-beta07
You have to apply Modifier.height(IntrinsicSize.Min)
to the Row
and the fillMaxHeight()
modifier to the 2nd Box
.
Something like:
Card(shape = RoundedCornerShape(8.dp)) {
Row(
modifier = Modifier.height(IntrinsicSize.Min) //Intrinsic measurement
) {
Box(
Modifier
.background(Color.Yellow)
.weight(1f)
) {
//Box(Modifier.height(50.dp))
}
Box(
Modifier
.width(20.dp)
.fillMaxHeight() //<--- fill max height
.background(Color.Green)
) {
//........
}
}
}
As explained in the doc:
The Row composable's
minIntrinsicHeight
will be the maximumminIntrinsicHeight
of its children. The GreenBox
element'sminIntrinsicHeight
is0
as it doesn't occupy space if no constraints are given; the YellowBox
minIntrinsicHeight
will be that of the content given a specific width. Therefore, theRow
element's height constraint will be the maxminIntrinsicHeight
of the YellowBox
content. The GreenBox
will then expand its height to the height constraint given by theRow
.