We just launched Compose Examples featuring over 150+ components! Check it out →

absoluteOffset

Common

Modifier in Compose Foundation Layout

Offset the content by ([x] dp, [y] dp). The offsets can be positive as well as non-positive. Applying an offset only changes the position of the content, without interfering with its size measurement.

This modifier will not consider layout direction when calculating the position of the content: a positive [x] offset will always move the content to the right. For a modifier that considers the layout direction when applying the offset, see [offset].

Last updated:

Installation

dependencies {
   implementation("androidx.compose.foundation:foundation-layout:1.8.0-alpha04")
}

Overloads

@Stable
fun Modifier.absoluteOffset(x: Dp = 0.dp, y: Dp = 0.dp)

fun Modifier.absoluteOffset(offset: Density.() -> IntOffset)

Code Examples

AbsoluteOffsetModifier

@Composable
fun AbsoluteOffsetModifier() {
    // This text will be offset (10.dp, 20.dp) from the center of the available space.
    Text(
        "Layout offset modifier sample",
        Modifier.fillMaxSize().wrapContentSize(Alignment.Center).absoluteOffset(10.dp, 20.dp)
    )
}

AbsoluteOffsetPxModifier

@Composable
fun AbsoluteOffsetPxModifier() {
    // This text will be offset in steps of 10.dp from the top left of the available space.
    var offset by remember { mutableStateOf(0) }
    Text(
        "Layout offset modifier sample",
        Modifier.clickable { offset += 10 }.absoluteOffset { IntOffset(offset, offset) }
    )
}
by @alexstyl