I'm learning Jetpack Compose and working with Android Studio's preview feature. When I hover over a Text
composable that has padding applied, the layout bounds (blue outline) only show the text content area and don't include the padding space
@Preview
@Composable
fun Home(modifier: Modifier = Modifier) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = modifier
.background(Color.Magenta)
.size(400.dp)
.padding(50.dp)
) {
Text(
text = "Home",
modifier = modifier
.background(Color.Blue) // Outer background (padding area)
.padding(20.dp)
.background(Color.Red) // Inner background (text area)
)
Text(
"downnnnn",
modifier
.background(Color.Green)
.padding(20.dp)
.background(Color.Yellow)
)
Text(
"down",
modifier.padding(20.dp)
)
}
}
Any insights into why this happens and how to better debug layout bounds in Compose would be greatly appreciated! I'm currently learning Jetpack Compose and want to understand the layout system better.
Preview Image
This is expected behavior in Jetpack Compose Preview. When you hover over a composable, the layout bounds only show the measured content size, not the extra space added by padding. Padding just shifts the content inward, it doesn’t change the layout bounds shown in preview overlays.
To visualize the full space including padding, wrap the Text
in a Box
or use background colors (as you’re doing) to see the actual size visually. The layout system works correctly, it’s just the preview hover outline that doesn’t include padding.
For better debugging, use Modifier.border()
or Modifier.drawBehind {}
to draw custom outlines.