ConstrainScope
@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 |
Unit |
Adds top and bottom links towards a horizontal |
Unit |
Adds start and end links towards a vertical |
Unit |
centerHorizontallyTo(Adds start and end links towards the corresponding anchors of |
Unit |
centerTo(other: ConstrainedLayoutReference)Adds all start, top, end, bottom links towards the corresponding anchors of |
Unit |
centerVerticallyTo(Adds top and bottom links towards the corresponding anchors of |
Unit |
circular(other: ConstrainedLayoutReference, angle: Float, distance: Dp)Set a circular constraint relative to the center of |
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(Adds both start and end links towards other |
Unit |
linkTo(Adds both top and bottom links towards other |
Unit |
linkTo(Adds all start, top, end, bottom links towards other |
Unit |
|
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 |
The right anchor of the layout - can be constrained using |
@FloatRange(from = 0.0, to = 1.0) Float |
The transparency value when rendering the content. |
BaselineAnchorable |
The |
HorizontalAnchorable |
The bottom anchor of the layout - can be constrained using |
VerticalAnchorable |
The end anchor of the layout - can be constrained using |
Dimension |
The height of the |
@FloatRange(from = 0.0, to = 1.0) Float |
Applied when the widget has constraints on the |
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 |
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 |
HorizontalAnchorable |
The top anchor of the layout - can be constrained using |
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 |
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 |
Dimension |
The width of the |
Public functions
asDimension
fun Dp.asDimension(): Dimension
Convenience extension method to parse a Dp as a Dimension object.
| See also | |
|---|---|
value |
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.
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.
centerHorizontallyTo
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
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,
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
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,
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
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.
Public 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: @FloatRange(from = 0.0, to = 1.0) 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.
horizontalBias
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
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 | |
|---|---|
TransformOrigin |
pivotY
var pivotY: Float
The Y axis offset percent where the content is rotated and scaled.
| See also | |
|---|---|
TransformOrigin |
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.
verticalBias
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
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.