{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

PaddingKt

public final class PaddingKt


Summary

Public methods

static final @NonNull PaddingValues

Creates a padding of all dp along all 4 edges.

static final @NonNull PaddingValues
PaddingValues(@NonNull Dp horizontal, @NonNull Dp vertical)

Creates a padding of horizontal dp along the left and right edges, and of vertical dp along the top and bottom edges.

static final @NonNull PaddingValues
PaddingValues(
    @NonNull Dp start,
    @NonNull Dp top,
    @NonNull Dp end,
    @NonNull Dp bottom
)

Creates a padding to be applied along the edges inside a box.

static final @NonNull Modifier
absolutePadding(
    @NonNull Modifier receiver,
    @NonNull Dp left,
    @NonNull Dp top,
    @NonNull Dp right,
    @NonNull Dp bottom
)

Apply additional space along each edge of the content in Dp: left, top, right and bottom.

static final @NonNull Dp
calculateEndPadding(
    @NonNull PaddingValues receiver,
    @NonNull LayoutDirection layoutDirection
)

The padding to be applied along the end edge inside a box: along the right edge if the layout direction is LTR, or along the left edge for RTL.

static final @NonNull Dp
calculateStartPadding(
    @NonNull PaddingValues receiver,
    @NonNull LayoutDirection layoutDirection
)

The padding to be applied along the start edge inside a box: along the left edge if the layout direction is LTR, or along the right edge for RTL.

static final @NonNull Modifier
padding(@NonNull Modifier receiver, @NonNull Dp all)

Apply all dp of additional space along each edge of the content, left, top, right and bottom.

static final @NonNull Modifier
padding(@NonNull Modifier receiver, @NonNull PaddingValues paddingValues)

Apply PaddingValues to the component as additional space along each edge of the content's left, top, right and bottom.

static final @NonNull Modifier
padding(
    @NonNull Modifier receiver,
    @NonNull Dp horizontal,
    @NonNull Dp vertical
)

Apply horizontal dp space along the left and right edges of the content, and vertical dp space along the top and bottom edges.

static final @NonNull Modifier
padding(
    @NonNull Modifier receiver,
    @NonNull Dp start,
    @NonNull Dp top,
    @NonNull Dp end,
    @NonNull Dp bottom
)

Apply additional space along each edge of the content in Dp: start, top, end and bottom.

Public methods

PaddingValues

public static final @NonNull PaddingValues PaddingValues(@NonNull Dp all)

Creates a padding of all dp along all 4 edges.

PaddingValues

public static final @NonNull PaddingValues PaddingValues(@NonNull Dp horizontal, @NonNull Dp vertical)

Creates a padding of horizontal dp along the left and right edges, and of vertical dp along the top and bottom edges.

PaddingValues

public static final @NonNull PaddingValues PaddingValues(
    @NonNull Dp start,
    @NonNull Dp top,
    @NonNull Dp end,
    @NonNull Dp bottom
)

Creates a padding to be applied along the edges inside a box. In LTR contexts start will be applied along the left edge and end will be applied along the right edge. In RTL contexts, start will correspond to the right edge and end to the left.

absolutePadding

public static final @NonNull Modifier absolutePadding(
    @NonNull Modifier receiver,
    @NonNull Dp left,
    @NonNull Dp top,
    @NonNull Dp right,
    @NonNull Dp bottom
)

Apply additional space along each edge of the content in Dp: left, top, right and bottom. These paddings are applied without regard to the current LayoutDirection, see padding to apply relative paddings. Padding is applied before content measurement and takes precedence; content may only be as large as the remaining space.

Negative padding is not permitted — it will cause IllegalArgumentException. See Modifier.offset.

Example usage:

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.absolutePadding
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Box(Modifier.background(color = Color.Gray)) {
    Box(
        Modifier.absolutePadding(left = 20.dp, top = 30.dp, right = 20.dp, bottom = 30.dp)
            .size(50.dp)
            .background(Color.Blue)
    )
}

calculateEndPadding

public static final @NonNull Dp calculateEndPadding(
    @NonNull PaddingValues receiver,
    @NonNull LayoutDirection layoutDirection
)

The padding to be applied along the end edge inside a box: along the right edge if the layout direction is LTR, or along the left edge for RTL.

calculateStartPadding

public static final @NonNull Dp calculateStartPadding(
    @NonNull PaddingValues receiver,
    @NonNull LayoutDirection layoutDirection
)

The padding to be applied along the start edge inside a box: along the left edge if the layout direction is LTR, or along the right edge for RTL.

padding

public static final @NonNull Modifier padding(@NonNull Modifier receiver, @NonNull Dp all)

Apply all dp of additional space along each edge of the content, left, top, right and bottom. Padding is applied before content measurement and takes precedence; content may only be as large as the remaining space.

Negative padding is not permitted — it will cause IllegalArgumentException. See Modifier.offset.

Example usage:

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Box(Modifier.background(color = Color.Gray)) {
    Box(Modifier.padding(all = 20.dp).size(50.dp).background(Color.Blue))
}

padding

public static final @NonNull Modifier padding(@NonNull Modifier receiver, @NonNull PaddingValues paddingValues)

Apply PaddingValues to the component as additional space along each edge of the content's left, top, right and bottom. Padding is applied before content measurement and takes precedence; content may only be as large as the remaining space.

Negative padding is not permitted — it will cause IllegalArgumentException. See Modifier.offset.

Example usage:

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

val innerPadding = PaddingValues(top = 10.dp, start = 15.dp)
Box(Modifier.background(color = Color.Gray)) {
    Box(Modifier.padding(innerPadding).size(50.dp).background(Color.Blue))
}

padding

public static final @NonNull Modifier padding(
    @NonNull Modifier receiver,
    @NonNull Dp horizontal,
    @NonNull Dp vertical
)

Apply horizontal dp space along the left and right edges of the content, and vertical dp space along the top and bottom edges. Padding is applied before content measurement and takes precedence; content may only be as large as the remaining space.

Negative padding is not permitted — it will cause IllegalArgumentException. See Modifier.offset.

Example usage:

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Box(Modifier.background(color = Color.Gray)) {
    Box(
        Modifier
            .padding(horizontal = 20.dp, vertical = 30.dp)
            .size(50.dp)
            .background(Color.Blue)
    )
}

padding

public static final @NonNull Modifier padding(
    @NonNull Modifier receiver,
    @NonNull Dp start,
    @NonNull Dp top,
    @NonNull Dp end,
    @NonNull Dp bottom
)

Apply additional space along each edge of the content in Dp: start, top, end and bottom. The start and end edges will be determined by the current LayoutDirection. Padding is applied before content measurement and takes precedence; content may only be as large as the remaining space.

Negative padding is not permitted — it will cause IllegalArgumentException. See Modifier.offset.

Example usage:

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Box(Modifier.background(color = Color.Gray)) {
    Box(
        Modifier.padding(start = 20.dp, top = 30.dp, end = 20.dp, bottom = 30.dp)
            .size(50.dp)
            .background(Color.Blue)
    )
}