0Pricing
Android Academy · Lesson

Spacing with Padding

Use Modifier for spacing.

What Is Padding?

Padding is empty space added around a composable's content. It pushes content away from the edges so things do not feel cramped.

In Compose you add padding through a Modifier.

Text(
    text = "Hello",
    modifier = Modifier.padding(16.dp)
)

The dp Unit

Padding sizes use dp, short for density-independent pixels. dp looks the same physical size on every screen.

Write a number then .dp, such as 8.dp or 24.dp.

Modifier.padding(8.dp)

All lessons in this course

  1. Styling Text
  2. Buttons and Clicks
  3. Spacing with Padding
  4. Colors and MaterialTheme
← Back to Android Academy