Google is committed to advancing racial equity for Black communities. See how.

OnGloballyPositionedModifier

interface OnGloballyPositionedModifier : Modifier.Element
androidx.compose.ui.layout.OnGloballyPositionedModifier

A modifier whose onGloballyPositioned is called with the final LayoutCoordinates of the Layout when the global position of the content may have changed. Note that it will be called after a composition when the coordinates are finalized.

Usage example:

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.ui.layout.onGloballyPositioned

Column(
    Modifier.onGloballyPositioned { coordinates ->
        // This will be the size of the Column.
        coordinates.size
        // The position of the Column relative to the application window.
        coordinates.globalPosition
        // The position of the Column relative to the Compose root.
        coordinates.positionInRoot
        // These will be the alignment lines provided to the layout (empty here for Column).
        coordinates.providedAlignmentLines
        // This will a LayoutCoordinates instance corresponding to the parent of Column.
        coordinates.parentCoordinates
    }
) {
    Box(Modifier.preferredSize(20.dp).background(Color.Green))
    Box(Modifier.preferredSize(20.dp).background(Color.Blue))
}

Summary

Public methods
abstract Unit

Called with the final LayoutCoordinates of the Layout after measuring.

Inherited functions
Inherited extension functions
From androidx.compose.foundation.layout
Modifier
Modifier.absoluteOffset(x: Dp = 0.dp, y: Dp = 0.dp)

Offset the content by (x dp, y dp).

Modifier

Offset the content by offset px.

Modifier
Modifier.absoluteOffsetPx(x: State<Float> = mutableStateOf(0f), y: State<Float> = mutableStateOf(0f))

Modifier
Modifier.absolutePadding(left: Dp = 0.dp, top: Dp = 0.dp, right: Dp = 0.dp, bottom: Dp = 0.dp)

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

Modifier
Modifier.aspectRatio(@FloatRange(0.0, 3.4E38, false) ratio: Float, matchHeightConstraintsFirst: Boolean = false)

Attempts to size the content to match a specified aspect ratio by trying to match one of the incoming constraints in the following order: Constraints.maxWidth, Constraints.maxHeight, Constraints.minWidth, Constraints.minHeight if matchHeightConstraintsFirst is false (which is the default), or Constraints.maxHeight, Constraints.maxWidth, Constraints.minHeight, Constraints.minWidth if matchHeightConstraintsFirst is true.

Modifier
Modifier.defaultMinSizeConstraints(minWidth: Dp = Dp.Unspecified, minHeight: Dp = Dp.Unspecified)

Constrain the size of the wrapped layout only when it would be otherwise unconstrained: the minWidth and minHeight constraints are only applied when the incoming corresponding constraint is 0.

Modifier
Modifier.fillMaxHeight(@FloatRange(0.0, 1.0) fraction: Float = 1f)

Have the content fill (possibly only partially) the Constraints.maxHeight of the incoming measurement constraints, by setting the minimum height and the maximum height to be equal to the maximum height multiplied by fraction.

Modifier
Modifier.fillMaxSize(@FloatRange(0.0, 1.0) fraction: Float = 1f)

Have the content fill (possibly only partially) the Constraints.maxWidth and Constraints.maxHeight of the incoming measurement constraints, by setting the minimum width and the maximum width to be equal to the maximum width multiplied by fraction, as well as the minimum height and the maximum height to be equal to the maximum height multiplied by fraction.

Modifier
Modifier.fillMaxWidth(@FloatRange(0.0, 1.0) fraction: Float = 1f)

Have the content fill (possibly only partially) the Constraints.maxWidth of the incoming measurement constraints, by setting the minimum width and the maximum width to be equal to the maximum width multiplied by fraction.

Modifier
Modifier.height(height: Dp)

Declare the height of the content to be exactly heightdp.

Modifier
Modifier.heightIn(min: Dp = Dp.Unspecified, max: Dp = Dp.Unspecified)

Constrain the height of the content to be between mindp and maxdp.

Modifier
Modifier.offset(x: Dp = 0.dp, y: Dp = 0.dp)

Offset the content by (