offset
Functions summary
Functions
Modifier.offset
fun Modifier.offset(offset: Density.() -> IntOffset): Modifier
Offset the content by offset px. 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 is designed to be used for offsets that change, possibly due to user interactions. It avoids recomposition when the offset is changing, and also adds a graphics layer that prevents unnecessary redrawing of the context when the offset is changing.
This modifier will automatically adjust the horizontal offset according to the layout direction: when the LD is LTR, positive horizontal offsets will move the content to the right and when the LD is RTL, positive horizontal offsets will move the content to the left. For a modifier that offsets without considering layout direction, see absoluteOffset.
Example usage:
import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.offset import androidx.compose.material3.Text import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp // This text will be offset in steps of 10.dp from the top left of the available space in // left-to-right context, and from top right in right-to-left context. var offset by remember { mutableStateOf(0) } Text( "Layout offset modifier sample", Modifier.clickable { offset += 10 }.offset { IntOffset(offset, offset) }, )
| See also | |
|---|---|
absoluteOffset |
Modifier.offset
fun Modifier.offset(x: Dp = 0.dp, y: Dp = 0.dp): Modifier
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 automatically adjust the horizontal offset according to the layout direction: when the layout direction is LTR, positive x offsets will move the content to the right and when the layout direction is RTL, positive x offsets will move the content to the left. For a modifier that offsets without considering layout direction, see absoluteOffset.
Example usage:
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.material3.Text import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp // This text will be offset (10.dp, 20.dp) from the center of the available space. In the // right-to-left context, the offset will be (-10.dp, 20.dp). Text( "Layout offset modifier sample", Modifier.fillMaxSize().wrapContentSize(Alignment.Center).offset(10.dp, 20.dp), )
| See also | |
|---|---|
absoluteOffset |