Jeevan Deep Singh
04/04/2025, 10:49 AMthe red color box
? similar to something like clipChildren=false
in view system?
@Composable
fun MyBox() {
Box(
Modifier
.fillMaxWidth()
.height(1.dp) // Restrict the parent's height to 1.dp
) {
Box(
Modifier
.fillMaxWidth()
.height(8.dp) // Child is larger than the parent
.background(Color.Red)
)
}
}
Stylianos Gakis
04/04/2025, 11:22 AMJeevan Deep Singh
04/04/2025, 12:10 PM@Composable
fun MyBox() {
Box(
Modifier
.fillMaxWidth()
.height(1.dp) // Restrict the parent's height to 1.dp
) {
Box(
Modifier
.fillMaxWidth()
.requiredHeight(50.dp) // Child is larger than the parent
.background(Color.Red)
)
}
}
tried this, but this also doesn't seem to workNitesh Singh
04/04/2025, 12:26 PMNitesh Singh
04/04/2025, 12:27 PMStylianos Gakis
04/04/2025, 12:43 PMJonathan
04/04/2025, 1:02 PMModifier.drawBehind {}
I believe you can draw beyond the bounds of the attached composable. I’ve done this to draw custom drop shadows.
With that being said, you can only perform primitive drawing with this method. You cannot layout child Composables beyond the parents bounds. If you’re trying to draw a custom background this might be the method you want to explore.Stylianos Gakis
04/04/2025, 1:03 PMStylianos Gakis
04/04/2025, 1:27 PM@Preview
@Composable
private fun Preview() {
Surface {
Box(Modifier.size(100.dp), contentAlignment = Alignment.Center) {
Box(
Modifier
.fillMaxWidth()
.height(10.dp), // Restrict the parent's height to 10.dp
) {
Box(
Modifier
.fillMaxWidth()
.requiredHeight(50.dp) // Child is larger than the parent
.background(Color.Red),
)
}
}
}
}
Already gives the right result as shown in the screenshot.
So if you do not see the same thing, the mistake is not in this part of the code, but somewhere else.Stylianos Gakis
04/04/2025, 1:31 PM.border(1.dp, Color.Yellow)
in the "10.dp" box, just for illustration purposes, you get thisJeevan Deep Singh
04/04/2025, 1:34 PM