Stay organized with collections Save and categorize content based on your preferences.

ConstrainScope

@Stable class ConstrainScope
kotlin.Any
   ↳ androidx.constraintlayout.compose.ConstrainScope

Scope that can be used to constrain a layout.

Used within Modifier.constrainAs from the inline DSL API. And within constrain from the ConstraintSet-based API.

Summary

Public methods
Unit

Adds start and end links towards a vertical anchor.

Unit

Adds top and bottom links towards a horizontal anchor.

Unit
centerHorizontallyTo(other: ConstrainedLayoutReference, @FloatRange(0.0, 1.0) bias: Float = 0.5f)

Adds start and end links towards the corresponding anchors of other.

Unit

Adds all start, top, end, bottom links towards the corresponding anchors of other.

Unit
centerVerticallyTo(other: ConstrainedLayoutReference, @FloatRange(0.0, 1.0) bias: Float = 0.5f)

Adds top and bottom links towards the corresponding anchors of other.

Unit
circular(other: ConstrainedLayoutReference, angle: Float, distance: Dp)

Set a circular constraint relative to the center of other.

Unit

Clear all constraints (vertical, horizontal, circular).

Unit

Clear the constraints on the horizontal axis (left, right, start, end).

Unit

Clear the constraints on the vertical axis (top, bottom, baseline).

Unit
linkTo(start: ConstraintLayoutBaseScope.VerticalAnchor, end: ConstraintLayoutBaseScope.VerticalAnchor, startMargin: Dp = 0.dp, endMargin: Dp = 0.dp, startGoneMargin: Dp = 0.dp, endGoneMargin: Dp = 0.dp, @FloatRange(0.0, 1.0) bias: Float = 0.5f)

Adds both start and end links towards other ConstraintLayoutBaseScope.VerticalAnchors.

Unit
linkTo(top: ConstraintLayoutBaseScope.HorizontalAnchor, bottom: ConstraintLayoutBaseScope.HorizontalAnchor, topMargin: Dp = 0.dp, bottomMargin: Dp = 0.dp, topGoneMargin: Dp = 0.dp, bottomGoneMargin: Dp = 0.dp, @FloatRange(0.0, 1.0) bias: Float = 0.5f)

Adds both top and bottom links towards other ConstraintLayoutBaseScope.HorizontalAnchors.

Unit
linkTo(start: ConstraintLayoutBaseScope.VerticalAnchor, top: ConstraintLayoutBaseScope.HorizontalAnchor, end: ConstraintLayoutBaseScope.VerticalAnchor, bottom: ConstraintLayoutBaseScope.HorizontalAnchor, startMargin: Dp = 0.dp, topMargin: Dp = 0.dp, endMargin: Dp = 0.dp, bottomMargin: Dp = 0.dp, startGoneMargin: Dp = 0.dp, topGoneMargin: Dp = 0.dp, endGoneMargin: Dp = 0.dp, bottomGoneMargin: Dp = 0.dp, @FloatRange(0.0, 1.0) horizontalBias: Float = 0.5f, @FloatRange(0.0, 1.0) verticalBias: Float = 0.5f)

Adds all start, top, end, bottom links towards other ConstraintLayoutBaseScope.HorizontalAnchors.

Unit

Resets the width and height to their default values.

Unit

Reset all render-time transforms of the content to their default values.

Properties
VerticalAnchorable

The left anchor of the layout - can be constrained using VerticalAnchorable.linkTo.

VerticalAnchorable

The right anchor of the layout - can be constrained using VerticalAnchorable.linkTo.

Float

The transparency value when rendering the content.

BaselineAnchorable

The FirstBaseline of the layout - can be constrained using BaselineAnchorable.linkTo.

HorizontalAnchorable

The bottom anchor of the layout - can be constrained using HorizontalAnchorable.linkTo.

VerticalAnchorable

The end anchor of the layout - can be constrained using VerticalAnchorable.linkTo.

Dimension

The height of the ConstraintLayout child.

Float

Whenever the width is not fixed, this weight may be used by an horizontal Chain to decide how much space assign to this widget.

ConstrainedLayoutReference

Reference to the ConstraintLayout itself, which can be used to specify constraints between itself and its children.

Float

The X axis offset percent where the content is rotated and scaled.

Float

The Y axis offset percent where the content is rotated and scaled.

Float

The degrees to rotate the content over the horizontal axis.

Float

The degrees to rotate the content over the vertical axis.

Float

The degrees to rotate the content on the screen plane.

Float

The percent scaling value on the horizontal axis.

Float

The percent scaling value on the vertical axis.

VerticalAnchorable

The start anchor of the layout - can be constrained using VerticalAnchorable.linkTo.

HorizontalAnchorable

The top anchor of the layout - can be constrained using HorizontalAnchorable.linkTo.

Dp

The distance to offset the content over the X axis.

Dp

The distance to offset the content over the Y axis.

Dp

The distance to offset the content over the Z axis.

Float

Whenever the height is not fixed, this weight may be used by a vertical Chain to decide how much space assign to this widget.

Visibility

The overall visibility of the ConstraintLayout child.

Dimension

The width of the ConstraintLayout child.

Public methods

centerAround

fun centerAround(anchor: ConstraintLayoutBaseScope.VerticalAnchor): Unit

Adds start and end links towards a vertical anchor. This will center the current layout around the vertical anchor.

centerAround

fun centerAround(anchor: ConstraintLayoutBaseScope.HorizontalAnchor): Unit

Adds top and bottom links towards a horizontal anchor. This will center the current layout around the horizontal anchor.

centerHorizontallyTo

fun centerHorizontallyTo(
    other: ConstrainedLayoutReference,
    @FloatRange(0.0, 1.0) bias: Float = 0.5f
): Unit

Adds start and end links towards the corresponding anchors of other. This will center horizontally the current layout inside or around (depending on size) other.

centerTo

fun centerTo(other: ConstrainedLayoutReference): Unit

Adds all start, top, end, bottom links towards the corresponding anchors of other. This will center the current layout inside or around (depending on size) other.

centerVerticallyTo

fun centerVerticallyTo(
    other: ConstrainedLayoutReference,
    @FloatRange(0.0, 1.0) bias: Float = 0.5f
): Unit

Adds top and bottom links towards the corresponding anchors of other. This will center vertically the current layout inside or around (depending on size) other.

circular

fun circular(
    other: ConstrainedLayoutReference,
    angle: Float,
    distance: Dp
): Unit

Set a circular constraint relative to the center of other. This will position the current widget at a relative angle and distance from other.

clearConstraints

fun clearConstraints(): Unit

Clear all constraints (vertical, horizontal, circular).

Useful when extending another ConstraintSet with unwanted constraints applied.

clearHorizontal

fun clearHorizontal(): Unit

Clear the constraints on the horizontal axis (left, right, start, end).

Useful when extending another ConstraintSet with unwanted constraints on this axis.

clearVertical

fun clearVertical(): Unit

Clear the constraints on the vertical axis (top, bottom, baseline).

Useful when extending another ConstraintSet with unwanted constraints on this axis.

linkTo

fun linkTo(
    start: ConstraintLayoutBaseScope.VerticalAnchor,
    end: ConstraintLayoutBaseScope.VerticalAnchor,
    startMargin: Dp = 0.dp,
    endMargin: Dp = 0.dp,
    startGoneMargin: Dp = 0.dp,
    endGoneMargin: Dp = 0.dp,
    @FloatRange(0.0, 1.0) bias: Float = 0.5f
): Unit

Adds both start and end links towards other ConstraintLayoutBaseScope.VerticalAnchors.

linkTo

fun linkTo(
    top: ConstraintLayoutBaseScope.HorizontalAnchor,
    bottom: ConstraintLayoutBaseScope.HorizontalAnchor,
    topMargin: Dp = 0.dp,
    bottomMargin: Dp = 0.dp,
    topGoneMargin: Dp = 0.dp,
    bottomGoneMargin: Dp = 0.dp,
    @FloatRange(0.0, 1.0) bias: Float = 0.5f
): Unit

Adds both top and bottom links towards other ConstraintLayoutBaseScope.HorizontalAnchors.

linkTo

fun linkTo(
    start: ConstraintLayoutBaseScope.VerticalAnchor,
    top: ConstraintLayoutBaseScope.HorizontalAnchor,
    end: ConstraintLayoutBaseScope.VerticalAnchor,
    bottom: ConstraintLayoutBaseScope.HorizontalAnchor,
    startMargin: Dp = 0.dp,
    topMargin: Dp = 0.dp,
    endMargin: Dp = 0.dp,
    bottomMargin: Dp = 0.dp,
    startGoneMargin: Dp = 0.dp,
    topGoneMargin: Dp = 0.dp,
    endGoneMargin: Dp = 0.dp,
    bottomGoneMargin: Dp = 0.dp,
    @FloatRange(0.0, 1.0) horizontalBias: Float = 0.5f,
    @FloatRange(0.0, 1.0) verticalBias: Float = 0.5f
): Unit

Adds all start, top, end, bottom links towards other ConstraintLayoutBaseScope.HorizontalAnchors.

resetDimensions

fun resetDimensions(): Unit

Resets the width and height to their default values.

Useful when extending another ConstraintSet with unwanted dimensions.

resetTransforms

fun resetTransforms(): Unit

Reset all render-time transforms of the content to their default values.

Does not modify the visibility property.

Useful when extending another ConstraintSet with unwanted transforms applied.

Properties

absoluteLeft

val absoluteLeft: VerticalAnchorable

The left anchor of the layout - can be constrained using VerticalAnchorable.linkTo.

absoluteRight

val absoluteRight: VerticalAnchorable

The right anchor of the layout - can be constrained using VerticalAnchorable.linkTo.

alpha

var alpha: Float

The transparency value when rendering the content.

baseline

val baseline: BaselineAnchorable

The FirstBaseline of the layout - can be constrained using BaselineAnchorable.linkTo.

bottom

val bottom: HorizontalAnchorable

The bottom anchor of the layout - can be constrained using HorizontalAnchorable.linkTo.

end

val end: VerticalAnchorable

The end anchor of the layout - can be constrained using VerticalAnchorable.linkTo.

height

var height: Dimension

The height of the ConstraintLayout child.

horizontalChainWeight

var horizontalChainWeight: Float

Whenever the width is not fixed, this weight may be used by an horizontal Chain to decide how much space assign to this widget.

parent

val parent: ConstrainedLayoutReference

Reference to the ConstraintLayout itself, which can be used to specify constraints between itself and its children.

pivotX

var pivotX: Float

The X axis offset percent where the content is rotated and scaled.

See Also

pivotY

var pivotY: Float

The Y axis offset percent where the content is rotated and scaled.

See Also

rotationX

var rotationX: Float

The degrees to rotate the content over the horizontal axis.

rotationY

var rotationY: Float

The degrees to rotate the content over the vertical axis.

rotationZ

var rotationZ: Float

The degrees to rotate the content on the screen plane.

scaleX

var scaleX: Float

The percent scaling value on the horizontal axis. Where 1 is 100%.

scaleY

var scaleY: Float

The percent scaling value on the vertical axis. Where 1 is 100%.

start

val start: VerticalAnchorable

The start anchor of the layout - can be constrained using VerticalAnchorable.linkTo.

top

val top: HorizontalAnchorable

The top anchor of the layout - can be constrained using HorizontalAnchorable.linkTo.

translationX

var translationX: Dp

The distance to offset the content over the X axis.

translationY

var translationY: Dp

The distance to offset the content over the Y axis.

translationZ

var translationZ: Dp

The distance to offset the content over the Z axis.

verticalChainWeight

var verticalChainWeight: Float

Whenever the height is not fixed, this weight may be used by a vertical Chain to decide how much space assign to this widget.

visibility

var visibility: Visibility

The overall visibility of the ConstraintLayout child.

Visibility.Visible by default.

width

var width: Dimension

The width of the ConstraintLayout child.