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

androidx.compose.ui

Interfaces

Alignment

An interface to position a point inside a 2D box.

ContentDrawScope

Receiver scope for drawing content into a layout, where the content can be drawn between other canvas operations.

DrawCacheModifier

DrawModifier implementation that supports building a cache of objects to be referenced across draw calls

DrawLayerModifier

A Modifier.Element that makes content draw into a draw layer.

DrawModifier

A Modifier.Element that draws into the space of the layout.

FocusObserverModifier

A modifier that can be used to observe focus state changes.

FocusRequesterModifier

A modifier that can be used to pass in a FocusRequester that can be used to request focus state changes.

LayoutModifier

A Modifier.Element that changes how its wrapped content is measured and laid out.

Measurable

A part of the composition that can be measured.

MeasureScope

The receiver scope of a layout's measure lambda.

Modifier

An ordered, immutable collection of modifier elements that decorate or add behavior to Compose UI elements.

OnGloballyPositionedModifier

A modifier whose onGloballyPositioned is called with the final LayoutCoordinates of the Layout when the global position of the content may have changed.

OnPositionedModifier

OnRemeasuredModifier

A modifier whose onRemeasured is called when the layout content is remeasured.

ParentDataModifier

A Modifier that provides data to the parent Layout.

Remeasurement

This object is associated with a layout node and allows to execute some extra measure/layout actions which are needed for some complex layouts.

RemeasurementModifier

A Modifier.Element that provides a Remeasurement object associated with the layout node the modifier is applied to.

WithConstraintsScope

Receiver scope being used by the children parameter of WithConstraints

ZIndexModifier

A Modifier.Element that controls the drawing order for the children of the same layout parent.

Classes

AbsoluteAlignment

Represents an absolute positioning of a point inside a 2D box.

AlignmentLine

Defines an offset line that can be used by parent layouts to align and position their children.

CacheDrawScope

Handle to a drawing environment that enables caching of content based on the resolved size.

CombinedModifier

A node in a Modifier chain.

DrawResult

Holder to a callback to be invoked during draw operations.

HorizontalAlignmentLine

A horizontal AlignmentLine.

Placeable

A Placeable corresponds to a child layout that can be positioned by its parent layout.

TransformOrigin

A two-dimensional position represented as a fraction of the Layer's width and height

VerticalAlignmentLine

A vertical AlignmentLine.

Type-aliases

MeasureBlock

A function for performing layout measurement.

Top-level functions summary

Unit
Layout(children: () -> Unit, minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock, minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock, maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock, maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock, modifier: Modifier = Modifier, measureBlock: MeasureBlock)

Layout is the main core component for layout.

Unit
Layout(children: () -> Unit, modifier: Modifier = Modifier, measureBlock: MeasureBlock)

Layout is the main core component for layout.

Unit
Layout(children: () -> Unit, measureBlocks: LayoutNode.MeasureBlocks, modifier: Modifier = Modifier)

Layout is the main core component for layout.

LayoutNode.MeasureBlocks

Default LayoutNode.MeasureBlocks object implementation, providing intrinsic measurements that use the measure block replacing the measure calls with intrinsic measurement calls.

Unit
MultiMeasureLayout(modifier: Modifier = Modifier, children: () -> Unit, measureBlock: MeasureBlock)

TransformOrigin
TransformOrigin(pivotFractionX: Float, pivotFractionY: Float)

Constructs a TransformOrigin from the given fractional values from the Layer's width and height

Unit
WithConstraints(modifier: Modifier = Modifier, children: WithConstraintsScope.() -> Unit)

A composable that defines its own content according to the available space, based on the incoming constraints or the current LayoutDirection.

LayoutNode.MeasureBlocks
measureBlocksOf(minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock, minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock, maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock, maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock, measureBlock: MeasureBlock)

Creates an instance of LayoutNode.MeasureBlocks to pass to Layout given intrinsic measures and a measure block.

Extension functions summary

For Modifier
Modifier
Modifier.composed(inspectorInfo: InspectorInfo.() -> Unit = NoInspectorInfo, factory: Modifier.() -> Modifier)

Declare a just-in-time composition of a Modifier that will be composed for each element it modifies.

Modifier
Modifier.drawBehind(onDraw: DrawScope.() -> Unit)

Draw into a Canvas behind the modified content.

Modifier
Modifier.drawLayer(scaleX: Float = 1f, scaleY: Float = 1f, alpha: Float = 1f, translationX: Float = 0f, translationY: Float = 0f, shadowElevation: Float = 0f, rotationX: Float = 0f, rotationY: Float = 0f, rotationZ: Float = 0f, transformOrigin: TransformOrigin = TransformOrigin.Center, shape: Shape = RectangleShape, clip: Boolean = false)

Creates a DrawLayerModifier to have all content will be drawn into a new draw layer.

Modifier
Modifier.drawWithCache(onBuildDrawCache: CacheDrawScope.() -> DrawResult)

Draw into a DrawScope with content that is persisted across draw calls as long as the size of the drawing area is the same or any state objects that are read have not changed.

Modifier

Creates a DrawModifier that allows the developer to draw before or after the layout's contents.

Modifier

Add this modifier to a component to make it focusable.

Modifier
Modifier.focusObserver(onFocusChange: (FocusState) -> Unit)

Add this modifier to a component to observe focus state changes.

Modifier

Add this modifier to a component to observe changes to focus state.

Modifier

Creates a LayoutModifier that allows changing how the wrapped element is measured and laid out.

Modifier
Modifier.onGloballyPositioned(crossinline onGloballyPositioned: (LayoutCoordinates) -> Unit)

Invoke onGloballyPositioned with the LayoutCoordinates of the element when the global position of the content may have changed.

Modifier

Modifier
Modifier.onSizeChanged(crossinline onSizeChanged: (IntSize) -> Unit)

Invoke onSizeChanged with the size of the content after it has been measured.

Modifier

Creates a ZIndexModifier that controls the drawing order for the children of the same layout parent.

For Composer
Modifier

Materialize any instance-specific composed modifiers for applying to a raw tree node.

Top-level functions

Layout

@Composable fun Layout(
    children: () -> Unit,
    minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock,
    minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock,
    maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock,
    maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock,
    modifier: Modifier = Modifier,
    measureBlock: MeasureBlock
): Unit

Layout is the main core component for layout. It can be used to measure and position zero or more children.

Intrinsic measurement blocks define the intrinsic sizes of the current layout. These can be queried by the parent in order to understand, in specific cases, what constraints should the layout be measured with:

  • minIntrinsicWidthMeasureBlock defines the minimum width this layout can take, given a specific height, such that the content of the layout will be painted correctly
  • minIntrinsicHeightMeasureBlock defines the minimum height this layout can take, given a specific width, such that the content of the layout will be painted correctly
  • maxIntrinsicWidthMeasureBlock defines the minimum width such that increasing it further will not decrease the minimum intrinsic height
  • maxIntrinsicHeightMeasureBlock defines the minimum height such that increasing it further will not decrease the minimum intrinsic width

For a composable able to define its content according to the incoming constraints, see WithConstraints.

Example usage:

import androidx.compose.ui.Layout
import androidx.compose.ui.layout
import androidx.compose.ui.unit.Constraints

// We build a layout that will occupy twice as much space as its children,
// and will position them to be bottom right aligned.
Layout(
    children,
    minIntrinsicWidthMeasureBlock = { measurables, h ->
        // The min intrinsic width of this layout will be twice the largest min intrinsic
        // width of a child. Note that we call minIntrinsicWidth with h / 2 for children,
        // since we should be double the size of the children.
        (measurables.map { it.minIntrinsicWidth(h / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    minIntrinsicHeightMeasureBlock = { measurables, w ->
        (measurables.map { it.minIntrinsicHeight(w / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    maxIntrinsicWidthMeasureBlock = { measurables, h ->
        (measurables.map { it.maxIntrinsicHeight(h / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    maxIntrinsicHeightMeasureBlock = { measurables, w ->
        (measurables.map { it.maxIntrinsicHeight(w / 2) }.maxByOrNull { it } ?: 0) * 2
    }
) { measurables, constraints ->
    // measurables contains one element corresponding to each of our layout children.
    // constraints are the constraints that our parent is currently measuring us with.
    val childConstraints = Constraints(
        minWidth = constraints.minWidth / 2,
        minHeight = constraints.minHeight / 2,
        maxWidth = constraints.maxWidth / 2,
        maxHeight = constraints.maxHeight / 2
    )
    // We measure the children with half our constraints, to ensure we can be double
    // the size of the children.
    val placeables = measurables.map { it.measure(childConstraints) }
    val layoutWidth = (placeables.maxByOrNull { it.width }?.width ?: 0) * 2
    val layoutHeight = (placeables.maxByOrNull { it.height }?.height ?: 0) * 2
    // We call layout to set the size of the current layout and to provide the positioning
    // of the children. The children are placed relative to the current layout place.
    layout(layoutWidth, layoutHeight) {
        placeables.forEach {
            it.placeRelative(layoutWidth - it.width, layoutHeight - it.height)
        }
    }
}
Parameters
children: () -> Unit The children composable to be laid out.
modifier: Modifier = Modifier Modifiers to be applied to the layout.
minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock The minimum intrinsic width of the layout.
minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock The minimum intrinsic height of the layout.
maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock The maximum intrinsic width of the layout.
maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock The maximum intrinsic height of the layout.
measureBlock: MeasureBlock The block defining the measurement and positioning of the layout.

Layout

@Composable fun Layout(
    children: () -> Unit,
    modifier: Modifier = Modifier,
    measureBlock: MeasureBlock
): Unit

Layout is the main core component for layout. It can be used to measure and position zero or more children.

The intrinsic measurements of this layout will be calculated by running the measureBlock, while swapping measure calls with appropriate intrinsic measurements. Note that these provided implementations will not be accurate in all cases - when this happens, the other overload of Layout should be used to provide correct measurements.

For a composable able to define its content according to the incoming constraints, see WithConstraints.

Example usage:

import androidx.compose.ui.Layout
import androidx.compose.ui.layout
import androidx.compose.ui.unit.Constraints

// We build a layout that will occupy twice as much space as its children,
// and will position them to be bottom right aligned.
Layout(children) { measurables, constraints ->
    // measurables contains one element corresponding to each of our layout children.
    // constraints are the constraints that our parent is currently measuring us with.
    val childConstraints = Constraints(
        minWidth = constraints.minWidth / 2,
        minHeight = constraints.minHeight / 2,
        maxWidth = constraints.maxWidth / 2,
        maxHeight = constraints.maxHeight / 2
    )
    // We measure the children with half our constraints, to ensure we can be double
    // the size of the children.
    val placeables = measurables.map { it.measure(childConstraints) }
    val layoutWidth = (placeables.maxByOrNull { it.width }?.width ?: 0) * 2
    val layoutHeight = (placeables.maxByOrNull { it.height }?.height ?: 0) * 2
    // We call layout to set the size of the current layout and to provide the positioning
    // of the children. The children are placed relative to the current layout place.
    layout(layoutWidth, layoutHeight) {
        placeables.forEach {
            it.placeRelative(layoutWidth - it.width, layoutHeight - it.height)
        }
    }
}
Parameters
children: () -> Unit The children composable to be laid out.
modifier: Modifier = Modifier Modifiers to be applied to the layout.
measureBlock: MeasureBlock The block defining the measurement and positioning of the layout.

Layout

@Composable inline fun Layout(
    children: () -> Unit,
    measureBlocks: LayoutNode.MeasureBlocks,
    modifier: Modifier = Modifier
): Unit

Layout is the main core component for layout. It can be used to measure and position zero or more children.

The intrinsic measurements of this layout will be calculated by using the measureBlocks instance.

For a composable able to define its content according to the incoming constraints, see WithConstraints.

Example usage:

import androidx.compose.ui.Layout
import androidx.compose.ui.layout
import androidx.compose.ui.measureBlocksOf
import androidx.compose.ui.unit.Constraints

val measureBlocks = measureBlocksOf(
    minIntrinsicWidthMeasureBlock = { measurables, h ->
        // The min intrinsic width of this layout will be twice the largest min intrinsic
        // width of a child. Note that we call minIntrinsicWidth with h / 2 for children,
        // since we should be double the size of the children.
        (measurables.map { it.minIntrinsicWidth(h / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    minIntrinsicHeightMeasureBlock = { measurables, w ->
        (measurables.map { it.minIntrinsicHeight(w / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    maxIntrinsicWidthMeasureBlock = { measurables, h ->
        (measurables.map { it.maxIntrinsicHeight(h / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    maxIntrinsicHeightMeasureBlock = { measurables, w ->
        (measurables.map { it.maxIntrinsicHeight(w / 2) }.maxByOrNull { it } ?: 0) * 2
    }
) { measurables, constraints ->
    // measurables contains one element corresponding to each of our layout children.
    // constraints are the constraints that our parent is currently measuring us with.
    val childConstraints = Constraints(
        minWidth = constraints.minWidth / 2,
        minHeight = constraints.minHeight / 2,
        maxWidth = constraints.maxWidth / 2,
        maxHeight = constraints.maxHeight / 2
    )
    // We measure the children with half our constraints, to ensure we can be double
    // the size of the children.
    val placeables = measurables.map { it.measure(childConstraints) }
    val layoutWidth = (placeables.maxByOrNull { it.width }?.width ?: 0) * 2
    val layoutHeight = (placeables.maxByOrNull { it.height }?.height ?: 0) * 2
    // We call layout to set the size of the current layout and to provide the positioning
    // of the children. The children are placed relative to the current layout place.
    layout(layoutWidth, layoutHeight) {
        placeables.forEach {
            it.placeRelative(layoutWidth - it.width, layoutHeight - it.height)
        }
    }
}
Layout(children = children, measureBlocks = measureBlocks)
Parameters
children: () -> Unit The children composable to be laid out.
modifier: Modifier = Modifier Modifiers to be applied to the layout.
measureBlocks: LayoutNode.MeasureBlocks An LayoutNode.MeasureBlocks instance defining the measurement and positioning of the layout.

Mea