ConstraintProperties


class ConstraintProperties


Added in 2.0

ConstraintProperties provides an easy to use api to update the layout params of ConstraintLayout children

Summary

Constants

const Int

The baseline of the text in a view.

const Int
BOTTOM = 4

The bottom side of a view.

const Int
END = 7

The right side of a view in left to right languages.

const Int
LEFT = 1

The left side of a view.

const Int

Dimension will be controlled by constraints

const Int

Calculate the size of a view in 0 dp by reducing the constrains gaps as much as possible

const Int

How to calculate the size of a view in 0 dp by using its wrap_content size

const Int

References the id of the parent.

const Int
RIGHT = 2

The right side of a view.

const Int
START = 6

The left side of a view in left to right languages.

const Int
TOP = 3

The top of a view.

const Int
UNSET = -1

Used to indicate a parameter is cleared or not set

const Int

Dimension will set by the view's content

Public constructors

Public functions

ConstraintProperties!
addToHorizontalChain(leftId: Int, rightId: Int)

Adds the view to a horizontal chain.

ConstraintProperties!
addToHorizontalChainRTL(leftId: Int, rightId: Int)

Adds the view to a horizontal chain using RTL attributes.

ConstraintProperties!
addToVerticalChain(topId: Int, bottomId: Int)

Adds a view to a vertical chain.

ConstraintProperties!
alpha(alpha: Float)

Adjust the alpha of a view.

Unit

Should be called to apply the changes currently a no op in place for subclasses and future use

ConstraintProperties!
center(
    firstID: Int,
    firstSide: Int,
    firstMargin: Int,
    secondId: Int,
    secondSide: Int,
    secondMargin: Int,
    bias: Float
)

Center view between the other two widgets.

ConstraintProperties!

Centers the view horizontally relative to toView's position.

ConstraintProperties!
centerHorizontally(
    leftId: Int,
    leftSide: Int,
    leftMargin: Int,
    rightId: Int,
    rightSide: Int,
    rightMargin: Int,
    bias: Float
)

Centers the widget horizontally to the left and right side on another widgets sides.

ConstraintProperties!

Centers the view horizontally relative to toView's position.

ConstraintProperties!
centerHorizontallyRtl(
    startId: Int,
    startSide: Int,
    startMargin: Int,
    endId: Int,
    endSide: Int,
    endMargin: Int,
    bias: Float
)

Centers the widgets horizontally to the left and right side on another widgets sides.

ConstraintProperties!

Centers the view vertically relative to toView's position.

ConstraintProperties!
centerVertically(
    topId: Int,
    topSide: Int,
    topMargin: Int,
    bottomId: Int,
    bottomSide: Int,
    bottomMargin: Int,
    bias: Float
)

Centers the widgets Vertically to the top and bottom side on another widgets sides.

ConstraintProperties!
connect(startSide: Int, endID: Int, endSide: Int, margin: Int)

Create a constraint between two widgets.

ConstraintProperties!

Sets how the height is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD.

ConstraintProperties!

Sets how the width is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD.

ConstraintProperties!

Sets the height of the view.

ConstraintProperties!

Sets the maximum height of the view.

ConstraintProperties!

Sets the maximum width of the view.

ConstraintProperties!

Sets the minimum height of the view.

ConstraintProperties!

Sets the minimum width of the view.

ConstraintProperties!

Sets the width of the view.

ConstraintProperties!

Constrains the views aspect ratio.

ConstraintProperties!
elevation(elevation: Float)

Set the elevation of a view.

ConstraintProperties!
goneMargin(anchor: Int, value: Int)

Sets the gone margin.

ConstraintProperties!

Adjust the horizontal bias of the view (used with views constrained on left and right).

ConstraintProperties!

How the elements of the horizontal chain will be positioned.

ConstraintProperties!

The child's weight that we can use to distribute the available horizontal space in a chain, if the dimension behaviour is set to MATCH_CONSTRAINT

ConstraintProperties!
margin(anchor: Int, value: Int)

Sets the margin.

ConstraintProperties!

Remove a constraint from this view.

ConstraintProperties!

Removes a view from a vertical chain.

ConstraintProperties!

Removes a view from a vertical chain.

ConstraintProperties!
rotation(rotation: Float)

Adjust the post-layout rotation about the Z axis of a view.

ConstraintProperties!
rotationX(rotationX: Float)

Adjust the post-layout rotation about the X axis of a view.

ConstraintProperties!
rotationY(rotationY: Float)

Adjust the post-layout rotation about the Y axis of a view.

ConstraintProperties!
scaleX(scaleX: Float)

Adjust the post-layout scale in X of a view.

ConstraintProperties!
scaleY(scaleY: Float)

Adjust the post-layout scale in Y of a view.

ConstraintProperties!
transformPivot(transformPivotX: Float, transformPivotY: Float)

Set X and Y location of the pivot point around which the view will rotate and scale.

ConstraintProperties!
transformPivotX(transformPivotX: Float)

Set X location of the pivot point around which the view will rotate and scale.

ConstraintProperties!
transformPivotY(transformPivotY: Float)

Set Y location of the pivot point around which the view will rotate and scale.

ConstraintProperties!
translation(translationX: Float, translationY: Float)

Adjust the post-layout X and Y translation of a view.

ConstraintProperties!
translationX(translationX: Float)

Adjust the post-layout X translation of a view.

ConstraintProperties!
translationY(translationY: Float)

Adjust the post-layout Y translation of a view.

ConstraintProperties!
translationZ(translationZ: Float)

Adjust the post-layout translation in Z of a view.

ConstraintProperties!

Adjust the vertical bias of the view (used with views constrained on left and right).

ConstraintProperties!
verticalChainStyle(chainStyle: Int)

How the elements of the vertical chain will be positioned. in a chain, if the dimension behaviour is set to MATCH_CONSTRAINT

ConstraintProperties!

The child's weight that we can use to distribute the available vertical space in a chain, if the dimension behaviour is set to MATCH_CONSTRAINT

ConstraintProperties!
visibility(visibility: Int)

Adjust the visibility of a view.

Constants

BASELINE

Added in 2.2.0-alpha13
const val BASELINE = 5: Int

The baseline of the text in a view.

BOTTOM

Added in 2.2.0-alpha13
const val BOTTOM = 4: Int

The bottom side of a view.

END

Added in 2.2.0-alpha13
const val END = 7: Int

The right side of a view in left to right languages. In right to left languages it corresponds to the left side of the view

LEFT

Added in 2.2.0-alpha13
const val LEFT = 1: Int

The left side of a view.

MATCH_CONSTRAINT

Added in 2.2.0-alpha13
const val MATCH_CONSTRAINT = 0: Int

Dimension will be controlled by constraints

MATCH_CONSTRAINT_SPREAD

Added in 2.2.0-alpha13
const val MATCH_CONSTRAINT_SPREAD = 0: Int

Calculate the size of a view in 0 dp by reducing the constrains gaps as much as possible

MATCH_CONSTRAINT_WRAP

Added in 2.2.0-alpha13
const val MATCH_CONSTRAINT_WRAP = 1: Int

How to calculate the size of a view in 0 dp by using its wrap_content size

PARENT_ID

Added in 2.2.0-alpha13
const val PARENT_ID = 0: Int

References the id of the parent.

RIGHT

Added in 2.2.0-alpha13
const val RIGHT = 2: Int

The right side of a view.

START

Added in 2.2.0-alpha13
const val START = 6: Int

The left side of a view in left to right languages. In right to left languages it corresponds to the right side of the view

TOP

Added in 2.2.0-alpha13
const val TOP = 3: Int

The top of a view.

UNSET

Added in 2.2.0-alpha13
const val UNSET = -1: Int

Used to indicate a parameter is cleared or not set

WRAP_CONTENT

Added in 2.2.0-alpha13
const val WRAP_CONTENT = -2: Int

Dimension will set by the view's content

Public constructors

ConstraintProperties

Added in 2.2.0-alpha13
ConstraintProperties(view: View!)

Public functions

addToHorizontalChain

Added in 2.2.0-alpha13
fun addToHorizontalChain(leftId: Int, rightId: Int): ConstraintProperties!

Adds the view to a horizontal chain.

Parameters
leftId: Int

id of the view in chain to the left

rightId: Int

id of the view in chain to the right

Returns
ConstraintProperties!

this

addToHorizontalChainRTL

Added in 2.2.0-alpha13
fun addToHorizontalChainRTL(leftId: Int, rightId: Int): ConstraintProperties!

Adds the view to a horizontal chain using RTL attributes.

Parameters
leftId: Int

id of the view in chain to the left

rightId: Int

id of the view in chain to the right

Returns
ConstraintProperties!

this

addToVerticalChain

Added in 2.2.0-alpha13
fun addToVerticalChain(topId: Int, bottomId: Int): ConstraintProperties!

Adds a view to a vertical chain.

Parameters
topId: Int

view above.

bottomId: Int

view below

Returns
ConstraintProperties!

this

alpha

Added in 2.2.0-alpha13
fun alpha(alpha: Float): ConstraintProperties!

Adjust the alpha of a view.

Parameters
alpha: Float

the alpha

Returns
ConstraintProperties!

this

apply

Added in 2.2.0-alpha13
fun apply(): Unit

Should be called to apply the changes currently a no op in place for subclasses and future use

center

Added in 2.2.0-alpha13
fun center(
    firstID: Int,
    firstSide: Int,
    firstMargin: Int,
    secondId: Int,
    secondSide: Int,
    secondMargin: Int,
    bias: Float
): ConstraintProperties!

Center view between the other two widgets.

Parameters
firstID: Int

ID of the first widget to connect the left or top of the widget to

firstSide: Int

the side of the widget to connect to

firstMargin: Int

the connection margin

secondId: Int

the ID of the second widget to connect to right or top of the widget to

secondSide: Int

the side of the widget to connect to

secondMargin: Int

the connection margin

bias: Float

the ratio between two connections

Returns
ConstraintProperties!

this

centerHorizontally

Added in 2.2.0-alpha13
fun centerHorizontally(toView: Int): ConstraintProperties!

Centers the view horizontally relative to toView's position.

Parameters
toView: Int

ID of view to center on (or in)

Returns
ConstraintProperties!

this

centerHorizontally

Added in 2.2.0-alpha13
fun centerHorizontally(
    leftId: Int,
    leftSide: Int,
    leftMargin: Int,
    rightId: Int,
    rightSide: Int,
    rightMargin: Int,
    bias: Float
): ConstraintProperties!

Centers the widget horizontally to the left and right side on another widgets sides.

Parameters
leftId: Int

The Id of the widget on the left side

leftSide: Int

The side of the leftId widget to connect to

leftMargin: Int

The margin on the left side

rightId: Int

The Id of the widget on the right side

rightSide: Int

The side of the rightId widget to connect to

rightMargin: Int

The margin on the right side

bias: Float

The ratio of the space on the left vs. right sides 0.5 is centered (default)

Returns
ConstraintProperties!

this

centerHorizontallyRtl

Added in 2.2.0-alpha13
fun centerHorizontallyRtl(toView: Int): ConstraintProperties!

Centers the view horizontally relative to toView's position.

Parameters
toView: Int

ID of view to center on (or in)

Returns
ConstraintProperties!

this

centerHorizontallyRtl

Added in 2.2.0-alpha13
fun centerHorizontallyRtl(
    startId: Int,
    startSide: Int,
    startMargin: Int,
    endId: Int,
    endSide: Int,
    endMargin: Int,
    bias: Float
): ConstraintProperties!

Centers the widgets horizontally to the left and right side on another widgets sides.

Parameters
startId: Int

The Id of the widget on the start side (left in non rtl languages)

startSide: Int

The side of the startId widget to connect to

startMargin: Int

The margin on the start side

endId: Int

The Id of the widget on the start side (left in non rtl languages)

endSide: Int

The side of the endId widget to connect to

endMargin: Int

The margin on the end side

bias: Float

The ratio of the space on the start vs end side 0.5 is centered (default)

Returns
ConstraintProperties!

this

centerVertically

Added in 2.2.0-alpha13
fun centerVertically(toView: Int): ConstraintProperties!

Centers the view vertically relative to toView's position.

Parameters
toView: Int

ID of view to center on (or in)

Returns
ConstraintProperties!

this

centerVertically

Added in 2.2.0-alpha13
fun centerVertically(
    topId: Int,
    topSide: Int,
    topMargin: Int,
    bottomId: Int,
    bottomSide: Int,
    bottomMargin: Int,
    bias: Float
): ConstraintProperties!

Centers the widgets Vertically to the top and bottom side on another widgets sides.

Parameters
topId: Int

The Id of the widget on the top side

topSide: Int

The side of the leftId widget to connect to

topMargin: Int

The margin on the top side

bottomId: Int

The Id of the widget on the bottom side

bottomSide: Int

The side of the bottomId widget to connect to

bottomMargin: Int

The margin on the bottom side

bias: Float

The ratio of the space on the top vs. bottom sides 0.5 is centered (default)

Returns
ConstraintProperties!

this

connect

Added in 2.2.0-alpha13
fun connect(startSide: Int, endID: Int, endSide: Int, margin: Int): ConstraintProperties!

Create a constraint between two widgets.

Parameters
startSide: Int

the side of the widget to constrain

endID: Int

the id of the widget to constrain to

endSide: Int

the side of widget to constrain to

margin: Int

the margin to constrain (margin must be positive)

constrainDefaultHeight

Added in 2.2.0-alpha13
fun constrainDefaultHeight(height: Int): ConstraintProperties!

Sets how the height is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD. Default is spread.

Parameters
height: Int

MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD

Returns
ConstraintProperties!

this

constrainDefaultWidth

Added in 2.2.0-alpha13
fun constrainDefaultWidth(width: Int): ConstraintProperties!

Sets how the width is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD. Default is spread.

Parameters
width: Int

MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD

Returns
ConstraintProperties!

this

constrainHeight

Added in 2.2.0-alpha13
fun constrainHeight(height: Int): ConstraintProperties!

Sets the height of the view.

Parameters
height: Int

the height of the view

Returns
ConstraintProperties!

this

constrainMaxHeight

Added in 2.2.0-alpha13
fun constrainMaxHeight(height: Int): ConstraintProperties!

Sets the maximum height of the view. It is a dimension, It is only applicable if height is #MATCH_CONSTRAINT}.

Parameters
height: Int

the maximum height of the view

Returns
ConstraintProperties!

this

constrainMaxWidth

Added in 2.2.0-alpha13
fun constrainMaxWidth(width: Int): ConstraintProperties!

Sets the maximum width of the view. It is a dimension, It is only applicable if height is #MATCH_CONSTRAINT}.

Parameters
width: Int

the maximum width of the view

Returns
ConstraintProperties!

this

constrainMinHeight

Added in 2.2.0-alpha13
fun constrainMinHeight(height: Int): ConstraintProperties!

Sets the minimum height of the view. It is a dimension, It is only applicable if height is #MATCH_CONSTRAINT}.

Parameters
height: Int

the minimum height of the view

Returns
ConstraintProperties!

this

constrainMinWidth

Added in 2.2.0-alpha13
fun constrainMinWidth(width: Int): ConstraintProperties!

Sets the minimum width of the view. It is a dimension, It is only applicable if height is #MATCH_CONSTRAINT}.

Parameters
width: Int

the minimum width of the view

Returns
ConstraintProperties!

this

constrainWidth

Added in 2.2.0-alpha13
fun constrainWidth(width: Int): ConstraintProperties!

Sets the width of the view.

Parameters
width: Int

the width of the view

Returns
ConstraintProperties!

this

dimensionRatio

Added in 2.2.0-alpha13
fun dimensionRatio(ratio: String!): ConstraintProperties!

Constrains the views aspect ratio. For Example a HD screen is 16 by 9 = 16/(float)9 = 1.777f.

Parameters
ratio: String!

The ratio of the width to height (width / height)

Returns
ConstraintProperties!

this

elevation

Added in 2.2.0-alpha13
fun elevation(elevation: Float): ConstraintProperties!

Set the elevation of a view.

Parameters
elevation: Float

the elevation

Returns
ConstraintProperties!

this

goneMargin

Added in 2.2.0-alpha13
fun goneMargin(anchor: Int, value: Int): ConstraintProperties!

Sets the gone margin.

Parameters
anchor: Int

The side to adjust the margin on

value: Int

The new value for the margin

Returns
ConstraintProperties!

this

horizontalBias

Added in 2.2.0-alpha13
fun horizontalBias(bias: Float): ConstraintProperties!

Adjust the horizontal bias of the view (used with views constrained on left and right).

Parameters
bias: Float

the new bias 0.5 is in the middle

Returns
ConstraintProperties!

this

horizontalChainStyle

Added in 2.2.0-alpha13
fun horizontalChainStyle(chainStyle: Int): ConstraintProperties!

How the elements of the horizontal chain will be positioned. If the dimension behaviour is set to MATCH_CONSTRAINT. The possible values are:

  • CHAIN_SPREAD -- the elements will be spread out
  • CHAIN_SPREAD_INSIDE -- similar, but the endpoints of the chain will not be spread out
  • CHAIN_PACKED -- the elements of the chain will be packed together. The horizontal bias attribute of the child will then affect the positioning of the packed elements
Parameters
chainStyle: Int

the weight that we can use to distribute the horizontal space

Returns
ConstraintProperties!

this

horizontalWeight

Added in 2.2.0-alpha13
fun horizontalWeight(weight: Float): ConstraintProperties!

The child's weight that we can use to distribute the available horizontal space in a chain, if the dimension behaviour is set to MATCH_CONSTRAINT

Parameters
weight: Float

the weight that we can use to distribute the horizontal space

Returns
ConstraintProperties!

this

margin

Added in 2.2.0-alpha13
fun margin(anchor: Int, value: Int): ConstraintProperties!

Sets the margin.

Parameters
anchor: Int

The side to adjust the margin on

value: Int

The new value for the margin

Returns
ConstraintProperties!

this

removeConstraints

Added in 2.2.0-alpha13
fun removeConstraints(anchor: Int): ConstraintProperties!

Remove a constraint from this view.

Parameters
anchor: Int

the Anchor to remove constraint from

Returns
ConstraintProperties!

this

removeFromHorizontalChain

Added in 2.2.0-alpha13
fun removeFromHorizontalChain(): ConstraintProperties!

Removes a view from a vertical chain. This assumes the view is connected to a vertical chain. Its behaviour is undefined if not part of a vertical chain.

Returns
ConstraintProperties!

this

removeFromVerticalChain

Added in 2.2.0-alpha13
fun removeFromVerticalChain(): ConstraintProperties!

Removes a view from a vertical chain. This assumes the view is connected to a vertical chain. Its behaviour is undefined if not part of a vertical chain.

Returns
ConstraintProperties!

this

rotation

Added in 2.2.0-alpha13
fun rotation(rotation: Float): ConstraintProperties!

Adjust the post-layout rotation about the Z axis of a view.

Parameters
rotation: Float

the rotation about the Z axis

Returns
ConstraintProperties!

this

rotationX

Added in 2.2.0-alpha13
fun rotationX(rotationX: Float): ConstraintProperties!

Adjust the post-layout rotation about the X axis of a view.

Parameters
rotationX: Float

the rotation about the X axis

Returns
ConstraintProperties!

this

rotationY

Added in 2.2.0-alpha13
fun rotationY(rotationY: Float): ConstraintProperties!

Adjust the post-layout rotation about the Y axis of a view.

Parameters
rotationY: Float

the rotation about the Y axis

Returns
ConstraintProperties!

this

scaleX

Added in 2.2.0-alpha13
fun scaleX(scaleX: Float): ConstraintProperties!

Adjust the post-layout scale in X of a view.

Parameters
scaleX: Float

the scale in X

Returns
ConstraintProperties!

this

scaleY

Added in 2.2.0-alpha13
fun scaleY(scaleY: Float): ConstraintProperties!

Adjust the post-layout scale in Y of a view.

Parameters
scaleY: Float

the scale in Y

Returns
ConstraintProperties!

this

transformPivot

Added in 2.2.0-alpha13
fun transformPivot(transformPivotX: Float, transformPivotY: Float): ConstraintProperties!

Set X and Y location of the pivot point around which the view will rotate and scale.

Parameters
transformPivotX: Float

X location of the pivot point.

transformPivotY: Float

Y location of the pivot point.

Returns
ConstraintProperties!

this

transformPivotX

Added in 2.2.0-alpha13
fun transformPivotX(transformPivotX: Float): ConstraintProperties!

Set X location of the pivot point around which the view will rotate and scale.

Parameters
transformPivotX: Float

X location of the pivot point.

Returns
ConstraintProperties!

this

transformPivotY

Added in 2.2.0-alpha13
fun transformPivotY(transformPivotY: Float): ConstraintProperties!

Set Y location of the pivot point around which the view will rotate and scale.

Parameters
transformPivotY: Float

Y location of the pivot point.

Returns
ConstraintProperties!

this

translation

Added in 2.2.0-alpha13
fun translation(translationX: Float, translationY: Float): ConstraintProperties!

Adjust the post-layout X and Y translation of a view.

Parameters
translationX: Float

the translation in X

translationY: Float

the translation in Y

Returns
ConstraintProperties!

this

translationX

Added in 2.2.0-alpha13
fun translationX(translationX: Float): ConstraintProperties!

Adjust the post-layout X translation of a view.

Parameters
translationX: Float

the translation in X

Returns
ConstraintProperties!

this

translationY

Added in 2.2.0-alpha13
fun translationY(translationY: Float): ConstraintProperties!

Adjust the post-layout Y translation of a view.

Parameters
translationY: Float

the translation in Y

Returns
ConstraintProperties!

this

translationZ

Added in 2.2.0-alpha13
fun translationZ(translationZ: Float): ConstraintProperties!

Adjust the post-layout translation in Z of a view. This is the preferred way to adjust the shadow.

Parameters
translationZ: Float

the translationZ

Returns
ConstraintProperties!

this

verticalBias

Added in 2.2.0-alpha13
fun verticalBias(bias: Float): ConstraintProperties!

Adjust the vertical bias of the view (used with views constrained on left and right).

Parameters
bias: Float

the new bias 0.5 is in the middle

Returns
ConstraintProperties!

this

verticalChainStyle

Added in 2.2.0-alpha13
fun verticalChainStyle(chainStyle: Int): ConstraintProperties!

How the elements of the vertical chain will be positioned. in a chain, if the dimension behaviour is set to MATCH_CONSTRAINT

  • CHAIN_SPREAD -- the elements will be spread out
  • CHAIN_SPREAD_INSIDE -- similar, but the endpoints of the chain will not be spread out
  • CHAIN_PACKED -- the elements of the chain will be packed together. The horizontal bias attribute of the child will then affect the positioning of the packed elements
Parameters
chainStyle: Int

the weight that we can use to distribute the horizontal space

Returns
ConstraintProperties!

this

verticalWeight

Added in 2.2.0-alpha13
fun verticalWeight(weight: Float): ConstraintProperties!

The child's weight that we can use to distribute the available vertical space in a chain, if the dimension behaviour is set to MATCH_CONSTRAINT

Parameters
weight: Float

the weight that we can use to distribute the vertical space

Returns
ConstraintProperties!

this

visibility

Added in 2.2.0-alpha13
fun visibility(visibility: Int): ConstraintProperties!

Adjust the visibility of a view.

Parameters
visibility: Int

the visibility (View.VISIBLE, View.INVISIBLE, View.GONE)

Returns
ConstraintProperties!

this