Colton Idle
10/07/2021, 4:19 AMColton Idle
10/07/2021, 4:20 AMColton Idle
10/07/2021, 4:21 AMColumn(
modifier = Modifier.padding(16.dp).width(148.dp).border(width = 1.dp, color = Color.White)) {
Box(modifier = Modifier.weight(.60f)) { Column() { Text(text = "Top 60%") } }
Box(modifier = Modifier.weight(.40f)) { Column { Text(text = "Bottom 40%") } }
}
Colton Idle
10/07/2021, 4:22 AMColton Idle
10/07/2021, 4:22 AMKaran Sharma
10/07/2021, 4:28 AM@Composable
fun DemoScreen() {
Column(
modifier = Modifier
.fillMaxWidth()
) {
Column(
modifier = Modifier
.fillMaxWidth()
.weight(.6f)
.background(color = Color.Green)
) {
Text(text = "60")
}
Column(
modifier = Modifier
.fillMaxWidth()
.weight(.4f)
.background(color = Color.Blue)
) {
Text(text = "40")
}
}
}
}Karan Sharma
10/07/2021, 4:28 AMKaran Sharma
10/07/2021, 4:29 AMColton Idle
10/07/2021, 4:31 AMKaran Sharma
10/07/2021, 4:33 AMAlbert Chang
10/07/2021, 4:39 AMColton Idle
10/07/2021, 4:41 AMAlbert Chang
10/07/2021, 4:45 AMColton Idle
10/07/2021, 4:47 AMColton Idle
10/07/2021, 4:55 AMBox(
modifier =
Modifier.padding(16.dp)
.aspectRatio(2 / 3F)
.border(width = 1.dp, color = Color.White)) {
But even that box by itself still expands to take up the full amount of space. 🤔Albert Chang
10/07/2021, 5:01 AMLayout(content = {
Text(text = "Top 60%")
Text(text = "Bottom 40%")
}) { measurables, constraints ->
val looseConstraints = constraints.copy(minWidth = 0, minHeight = 0)
val top = measurables[0].measure(looseConstraints)
val bottom = measurables[1].measure(looseConstraints)
val height = max(top.height / .6f, bottom.height / .4f).roundToInt()
layout(constraints.maxWidth, height) {
top.placeRelative(0, 0)
bottom.placeRelative(0, (height * .6f).roundToInt())
}
}
Colton Idle
10/07/2021, 5:02 AMColton Idle
10/07/2021, 5:02 AMAlbert Chang
10/07/2021, 5:03 AMColton Idle
10/07/2021, 5:06 AMColton Idle
10/07/2021, 5:07 AMAlbert Chang
10/07/2021, 5:10 AMColton Idle
10/07/2021, 5:10 AMAlbert Chang
10/07/2021, 5:17 AMColton Idle
10/07/2021, 5:19 AMgildor
10/07/2021, 5:45 AM