@LayoutScopeMarker
class 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 functions

Dimension

Convenience extension method to parse a Dp as a Dimension object.

Unit

Adds top and bottom links towards a horizontal anchor.

Unit

Adds start and end links towards a vertical anchor.

Unit
centerHorizontallyTo(
    other: ConstrainedLayoutReference,
    bias: @FloatRange(from = 0.0, to = 1.0) Float
)

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,
    bias: @FloatRange(from = 0.0, to = 1.0) Float
)

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,
    endMargin: Dp,
    startGoneMargin: Dp,
    endGoneMargin: Dp,
    bias: @FloatRange(from = 0.0, to = 1.0) Float
)

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

Unit
linkTo(
    top: ConstraintLayoutBaseScope.HorizontalAnchor,
    bottom: ConstraintLayoutBaseScope.HorizontalAnchor,
    topMargin: Dp,
    bottomMargin: Dp,
    topGoneMargin: Dp,
    bottomGoneMargin: Dp,
    bias: @FloatRange(from = 0.0, to = 1.0) Float
)

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,
    topMargin: Dp,
    endMargin: Dp,
    bottomMargin: Dp,
    startGoneMargin: Dp,
    topGoneMargin: Dp,
    endGoneMargin: Dp,
    bottomGoneMargin: Dp,
    horizontalBias: @FloatRange(from = 0.0, to = 1.0) Float,
    verticalBias: @FloatRange(from = 0.0, to = 1.0) Float
)

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.

Public 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.

@FloatRange(from = 0.0, to = 1.0) 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.

@FloatRange(from = 0.0, to = 1.0) Float

Applied when the widget has constraints on the start and end anchors.

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.

@FloatRange(from = 0.0, to = 1.0) Float

Applied when the widget has constraints on the top and bottom anchors.

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 functions

fun Dp.asDimension(): Dimension

Convenience extension method to parse a Dp as a Dimension object.

See also
value

centerAround

Added in 1.1.0
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.

centerAround

Added in 1.1.0
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.

centerHorizontallyTo

Added in 1.1.0
fun centerHorizontallyTo(
    other: ConstrainedLayoutReference,
    bias: @FloatRange(from = 0.0, to = 1.0) 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

Added in 1.1.0
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

Added in 1.1.0
fun centerVerticallyTo(
    other: ConstrainedLayoutReference,
    bias: @FloatRange(from = 0.0, to = 1.0) 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

Added in 1.1.0
fun clearConstraints(): Unit

Clear all constraints (vertical, horizontal, circular).

Useful when extending another ConstraintSet with unwanted constraints applied.

clearHorizontal

Added in 1.1.0
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

Added in 1.1.0
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,
    bias: @FloatRange(from = 0.0, to = 1.0) 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,
    bias: @FloatRange(from = 0.0, to = 1.0) 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,
    horizontalBias: @FloatRange(from = 0.0, to = 1.0) Float = 0.5f,
    verticalBias: @FloatRange(from = 0.0, to = 1.0) Float = 0.5f
): Unit

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

resetDimensions

Added in 1.1.0
fun resetDimensions(): Unit

Resets the width and height to their default values.

Useful when extending another ConstraintSet with unwanted dimensions.

resetTransforms

Added in 1.1.0
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.

Public properties

absoluteLeft

Added in 1.1.0
val absoluteLeftVerticalAnchorable

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

absoluteRight

Added in 1.1.0
val absoluteRightVerticalAnchorable

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

alpha

Added in 1.1.0
var alpha: @FloatRange(from = 0.0, to = 1.0) Float

The transparency value when rendering the content.

baseline

Added in 1.1.0
val baselineBaselineAnchorable

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

bottom

Added in 1.1.0
val bottomHorizontalAnchorable

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

end

Added in 1.1.0
val endVerticalAnchorable

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

height

Added in 1.1.0
var heightDimension

The height of the ConstraintLayout child.

horizontalBias

Added in 1.1.0
var horizontalBias: @FloatRange(from = 0.0, to = 1.0) Float

Applied when the widget has constraints on the start and end anchors. It defines the position of the widget relative to the space within the constraints, where 0f is the left-most position and 1f is the right-most position.

When layout direction is RTL, the value of the bias is effectively inverted.

E.g.: For horizontalBias = 0.3f, 0.7f is used for RTL.

Note that the bias may also be applied with calls such as linkTo.

horizontalChainWeight

Added in 1.1.0
var horizontalChainWeightFloat

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

Added in 1.1.0
val parentConstrainedLayoutReference

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

pivotX

Added in 1.1.0
var pivotXFloat

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

See also
TransformOrigin

pivotY

Added in 1.1.0
var pivotYFloat

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

See also
TransformOrigin

rotationX

Added in 1.1.0
var rotationXFloat

The degrees to rotate the content over the horizontal axis.

rotationY

Added in 1.1.0
var rotationYFloat

The degrees to rotate the content over the vertical axis.

rotationZ

Added in 1.1.0
var rotationZFloat

The degrees to rotate the content on the screen plane.

scaleX

Added in 1.1.0
var scaleXFloat

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

scaleY

Added in 1.1.0
var scaleYFloat

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

start

Added in 1.1.0
val startVerticalAnchorable

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

top

Added in 1.1.0
val topHorizontalAnchorable

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

translationX

Added in 1.1.0
var translationXDp

The distance to offset the content over the X axis.

translationY

Added in 1.1.0
var translationYDp

The distance to offset the content over the Y axis.

translationZ

Added in 1.1.0
var translationZDp

The distance to offset the content over the Z axis.

verticalBias

Added in 1.1.0
var verticalBias: @FloatRange(from = 0.0, to = 1.0) Float

Applied when the widget has constraints on the top and bottom anchors. It defines the position of the widget relative to the space within the constraints, where 0f is the top-most position and 1f is the bottom-most position.

verticalChainWeight

Added in 1.1.0
var verticalChainWeightFloat

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

Added in 1.1.0
var visibilityVisibility

The overall visibility of the ConstraintLayout child.

Visibility.Visible by default.

width

Added in 1.1.0
var widthDimension

The width of the ConstraintLayout child.