padding
Functions summary
Modifier |
Apply |
Cmn
|
Modifier |
Modifier.padding(paddingValues: PaddingValues)Apply |
Cmn
|
Modifier |
Apply |
Cmn
|
Modifier |
Apply additional space along each edge of the content in |
Cmn
|
Functions
Modifier.padding
fun Modifier.padding(all: Dp): Modifier
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)) }
Modifier.padding
fun Modifier.padding(paddingValues: PaddingValues): Modifier
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)) }
Modifier.padding
fun Modifier.padding(horizontal: Dp = 0.dp, vertical: Dp = 0.dp): Modifier
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) ) }
Modifier.padding
fun Modifier.padding(start: Dp = 0.dp, top: Dp = 0.dp, end: Dp = 0.dp, bottom: Dp = 0.dp): Modifier
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) ) }