MR3Y
11/23/2023, 10:04 PMModifier.layout {}
) is that it pushes the text beneath the row (red box + button) by the same offset amount leaving a weird vertical gap in between. Obviously offsetting the text upwards as well by the same amount doesn't solve the problem because it just moves that gap after the text. what I want to do is basically the same as the second picture but without that blank gap at the bottom.MR3Y
11/23/2023, 10:05 PM@Composable
fun Sample() {
Box(
modifier = Modifier
.wrapContentSize()
.background(Color.Blue)
) {
Column(
verticalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier
.padding(top = 80.dp)
.background(Color.White)
.padding(horizontal = 16.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Box(
modifier = Modifier
.size(128.dp)
.layout { measurable, constraints ->
val placeable = measurable.measure(constraints)
val offsetY = -(placeable.height / 2)
layout(constraints.maxWidth, placeable.height) {
placeable.placeRelative(0, offsetY)
}
}
.background(Color.Red)
)
ElevatedButton(
onClick = { /*TODO*/ },
shape = RoundedCornerShape(16.dp),
colors = ButtonDefaults.elevatedButtonColors(
containerColor = MaterialTheme.colorScheme.primary,
contentColor = MaterialTheme.colorScheme.onPrimary
),
modifier = Modifier.padding(vertical = 4.dp)
) {
Text(
text = "Button",
style = MaterialTheme.typography.labelLarge
)
}
}
Text(
text = "Text",
color = Color.Black,
fontSize = 32.sp
)
}
}
}
MR3Y
11/23/2023, 10:06 PMGreg Steckman
11/23/2023, 10:30 PMBox {
Box(modifier = Modifier.background(Color.Blue).height(64.dp + 16.dp).fillMaxWidth())
Column(
verticalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier
.padding(top = 16.dp)
.padding(horizontal = 16.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.Bottom
) {
Box(
modifier = Modifier.size(128.dp).background(Color.Red)
)
ElevatedButton(
onClick = { /*TODO*/ },
shape = RoundedCornerShape(16.dp),
colors = ButtonDefaults.elevatedButtonColors(
containerColor = MaterialTheme.colorScheme.primary,
contentColor = MaterialTheme.colorScheme.onPrimary
),
modifier = Modifier.padding(vertical = 4.dp)
) {
Text(
text = "Button",
style = MaterialTheme.typography.labelLarge
)
}
}
Text(
text = "Text",
color = Color.Black,
fontSize = 32.sp
)
}
}
MR3Y
11/23/2023, 10:50 PMMR3Y
11/23/2023, 11:23 PMmyanmarking
11/24/2023, 4:46 PMmyanmarking
11/24/2023, 4:46 PMMR3Y
11/24/2023, 5:49 PMoffset
doesn't affect layout.Greg Steckman
11/24/2023, 5:57 PMmyanmarking
11/24/2023, 5:59 PMMR3Y
11/24/2023, 6:14 PMModifier.offset
is a possible solution.MR3Y
11/24/2023, 6:14 PM