ConstraintLayout.LayoutParams

public static class ConstraintLayout.LayoutParams
extends ViewGroup.MarginLayoutParams

java.lang.Object
   ↳ android.view.ViewGroup.LayoutParams
     ↳ android.view.ViewGroup.MarginLayoutParams
       ↳ androidx.constraintlayout.widget.ConstraintLayout.LayoutParams


This class contains the different attributes specifying how a view want to be laid out inside a ConstraintLayout. For building up constraints at run time, using ConstraintSet is recommended.

Summary

Constants

int BASELINE

The baseline of the text in a view.

int BOTTOM

The bottom side of a view.

int CHAIN_PACKED

Chain packed style

int CHAIN_SPREAD

Chain spread style

int CHAIN_SPREAD_INSIDE

Chain spread inside style

int CIRCLE

Circle reference from a view.

int END

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

int HORIZONTAL

The horizontal orientation.

int LEFT

The left side of a view.

int MATCH_CONSTRAINT

Dimension will be controlled by constraints.

int MATCH_CONSTRAINT_PERCENT

Set matchConstraintDefault* percent to be based on a percent of another dimension (by default, the parent) Use to set the matchConstraintDefaultWidth and matchConstraintDefaultHeight

int MATCH_CONSTRAINT_SPREAD

Set matchConstraintDefault* spread as much as possible within its constraints.

int MATCH_CONSTRAINT_WRAP

Set matchConstraintDefault* default to the wrap content size.

int PARENT_ID

References the id of the parent.

int RIGHT

The right side of a view.

int START

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

int TOP

The top of a view.

int UNSET

Defines an id that is not set.

int VERTICAL

The vertical orientation.

int WRAP_BEHAVIOR_HORIZONTAL_ONLY

int WRAP_BEHAVIOR_INCLUDED

int WRAP_BEHAVIOR_SKIPPED

int WRAP_BEHAVIOR_VERTICAL_ONLY

Inherited constants

Fields

public int baselineMargin

The baseline margin.

public int baselineToBaseline

Constrains the baseline of a child to the baseline of a target child (contains the target child id).

public int baselineToBottom

Constrains the baseline of a child to the bottom of a target child (contains the target child id).

public int baselineToTop

Constrains the baseline of a child to the top of a target child (contains the target child id).

public int bottomToBottom

Constrains the bottom side of a child to the bottom side of a target child (contains the target child id).

public int bottomToTop

Constrains the bottom side of a child to the top side of a target child (contains the target child id).

public float circleAngle

The angle used for a circular constraint]

public int circleConstraint

Constrains the center of a child to the center of a target child (contains the target child id).

public int circleRadius

The radius used for a circular constraint

public boolean constrainedHeight

Specify if the vertical dimension is constrained in case both top & bottom constraints are set and the widget dimension is not a fixed dimension.

public boolean constrainedWidth

Specify if the horizontal dimension is constrained in case both left & right constraints are set and the widget dimension is not a fixed dimension.

public String constraintTag

Define a category of view to be used by helpers and motionLayout

public String dimensionRatio

The ratio information.

public int editorAbsoluteX

The design time location of the left side of the child.

public int editorAbsoluteY

The design time location of the right side of the child.

public int endToEnd

Constrains the end side of a child to the end side of a target child (contains the target child id).

public int endToStart

Constrains the end side of a child to the start side of a target child (contains the target child id).

public int goneBaselineMargin

The baseline margin to use when the target is gone.

public int goneBottomMargin

The bottom margin to use when the target is gone.

public int goneEndMargin

The end margin to use when the target is gone.

public int goneLeftMargin

The left margin to use when the target is gone.

public int goneRightMargin

The right margin to use when the target is gone

public int goneStartMargin

The start margin to use when the target is gone.

public int goneTopMargin

The top margin to use when the target is gone.

public int guideBegin

The distance of child (guideline) to the top or left edge of its parent.

public int guideEnd

The distance of child (guideline) to the top or left edge of its parent.

public float guidePercent

The ratio of the distance to the parent's sides

public boolean helped

public float horizontalBias

The ratio between two connections when the left and right (or start and end) sides are constrained.

public int horizontalChainStyle

If the child is the start of a horizontal chain, this attribute will drive how the elements of the chain will be positioned.

public float horizontalWeight

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

public int leftToLeft

Constrains the left side of a child to the left side of a target child (contains the target child id).

public int leftToRight

Constrains the left side of a child to the right side of a target child (contains the target child id).

public int matchConstraintDefaultHeight

Define how the widget vertical dimension is handled when set to MATCH_CONSTRAINT

public int matchConstraintDefaultWidth

Define how the widget horizontal dimension is handled when set to MATCH_CONSTRAINT

public int matchConstraintMaxHeight

Specify a maximum height size for the widget.

public int matchConstraintMaxWidth

Specify a maximum width size for the widget.

public int matchConstraintMinHeight

Specify a minimum height size for the widget.

public int matchConstraintMinWidth

Specify a minimum width size for the widget.

public float matchConstraintPercentHeight

Specify the percentage when using the match constraint percent mode.

public float matchConstraintPercentWidth

Specify the percentage when using the match constraint percent mode.

public int orientation

public int rightToLeft

Constrains the right side of a child to the left side of a target child (contains the target child id).

public int rightToRight

Constrains the right side of a child to the right side of a target child (contains the target child id).

public int startToEnd

Constrains the start side of a child to the end side of a target child (contains the target child id).

public int startToStart

Constrains the start side of a child to the start side of a target child (contains the target child id).

public int topToBottom

Constrains the top side of a child to the bottom side of a target child (contains the target child id).

public int topToTop

Constrains the top side of a child to the top side of a target child (contains the target child id).

public float verticalBias

The ratio between two connections when the top and bottom sides are constrained.

public int verticalChainStyle

If the child is the start of a vertical chain, this attribute will drive how the elements of the chain will be positioned.

public float verticalWeight

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

public int wrapBehaviorInParent

Specify how this view is taken in account during the parent's wrap computation Can be either of: WRAP_BEHAVIOR_INCLUDED the widget is taken in account for the wrap (default) WRAP_BEHAVIOR_HORIZONTAL_ONLY the widget will be included in the wrap only horizontally WRAP_BEHAVIOR_VERTICAL_ONLY the widget will be included in the wrap only vertically WRAP_BEHAVIOR_SKIPPED the widget is not part of the wrap computation

Inherited fields

Public constructors

LayoutParams(ConstraintLayout.LayoutParams source)

Create a LayoutParams base on an existing layout Params

LayoutParams(Context c, AttributeSet attrs)
LayoutParams(int width, int height)
LayoutParams(ViewGroup.LayoutParams source)

Public methods

String getConstraintTag()

Tag that can be used to identify a view as being a member of a group.

void reset()
void resolveLayoutDirection(int layoutDirection)

void validate()

Inherited methods

Constants

BASELINE

public static final int BASELINE

The baseline of the text in a view.

Constant Value: 5 (0x00000005)

BOTTOM

public static final int BOTTOM

The bottom side of a view.

Constant Value: 4 (0x00000004)

CHAIN_PACKED

public static final int CHAIN_PACKED

Chain packed style

Constant Value: 2 (0x00000002)

CHAIN_SPREAD

public static final int CHAIN_SPREAD

Chain spread style

Constant Value: 0 (0x00000000)

CHAIN_SPREAD_INSIDE

public static final int CHAIN_SPREAD_INSIDE

Chain spread inside style

Constant Value: 1 (0x00000001)

CIRCLE

public static final int CIRCLE

Circle reference from a view.

Constant Value: 8 (0x00000008)

END

public static final int END

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

Constant Value: 7 (0x00000007)

HORIZONTAL

public static final int HORIZONTAL

The horizontal orientation.

Constant Value: 0 (0x00000000)

LEFT

public static final int LEFT

The left side of a view.

Constant Value: 1 (0x00000001)

MATCH_CONSTRAINT

public static final int MATCH_CONSTRAINT

Dimension will be controlled by constraints.

Constant Value: 0 (0x00000000)

MATCH_CONSTRAINT_PERCENT

public static final int MATCH_CONSTRAINT_PERCENT

Set matchConstraintDefault* percent to be based on a percent of another dimension (by default, the parent) Use to set the matchConstraintDefaultWidth and matchConstraintDefaultHeight

Constant Value: 2 (0x00000002)

MATCH_CONSTRAINT_SPREAD

public static final int MATCH_CONSTRAINT_SPREAD

Set matchConstraintDefault* spread as much as possible within its constraints. Use to set the matchConstraintDefaultWidth and matchConstraintDefaultHeight

Constant Value: 0 (0x00000000)

MATCH_CONSTRAINT_WRAP

public static final int MATCH_CONSTRAINT_WRAP

Set matchConstraintDefault* default to the wrap content size. Use to set the matchConstraintDefaultWidth and matchConstraintDefaultHeight

Constant Value: 1 (0x00000001)

PARENT_ID

public static final int PARENT_ID

References the id of the parent.

Constant Value: 0 (0x00000000)

public static final int RIGHT

The right side of a view.

Constant Value: 2 (0x00000002)

START

public static final int START

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

Constant Value: 6 (0x00000006)

TOP

public static final int TOP

The top of a view.

Constant Value: 3 (0x00000003)

UNSET

public static final int UNSET

Defines an id that is not set.

Constant Value: -1 (0xffffffff)

VERTICAL

public static final int VERTICAL

The vertical orientation.

Constant Value: 1 (0x00000001)

WRAP_BEHAVIOR_HORIZONTAL_ONLY

public static final int WRAP_BEHAVIOR_HORIZONTAL_ONLY

Constant Value: 1 (0x00000001)

WRAP_BEHAVIOR_INCLUDED

public static final int WRAP_BEHAVIOR_INCLUDED

Constant Value: 0 (0x00000000)

WRAP_BEHAVIOR_SKIPPED

public static final int WRAP_BEHAVIOR_SKIPPED

Constant Value: 3 (0x00000003)

WRAP_BEHAVIOR_VERTICAL_ONLY

public static final int WRAP_BEHAVIOR_VERTICAL_ONLY

Constant Value: 2 (0x00000002)

Fields

baselineMargin

public int baselineMargin

The baseline margin.

baselineToBaseline

public int baselineToBaseline

Constrains the baseline of a child to the baseline of a target child (contains the target child id).

baselineToBottom

public int baselineToBottom

Constrains the baseline of a child to the bottom of a target child (contains the target child id).

baselineToTop

public int baselineToTop

Constrains the baseline of a child to the top of a target child (contains the target child id).

bottomToBottom

public int bottomToBottom

Constrains the bottom side of a child to the bottom side of a target child (contains the target child id).

bottomToTop

public int bottomToTop

Constrains the bottom side of a child to the top side of a target child (contains the target child id).

circleAngle

public float circleAngle

The angle used for a circular constraint]

circleConstraint

public int circleConstraint

Constrains the center of a child to the center of a target child (contains the target child id).

circleRadius

public int circleRadius

The radius used for a circular constraint

constrainedHeight

public boolean constrainedHeight

Specify if the vertical dimension is constrained in case both top & bottom constraints are set and the widget dimension is not a fixed dimension. By default, if a widget is set to WRAP_CONTENT, we will treat that dimension as a fixed dimension, meaning the dimension will not change regardless of constraints. Setting this attribute to true allows the dimension to change in order to respect constraints.

constrainedWidth

public boolean constrainedWidth

Specify if the horizontal dimension is constrained in case both left & right constraints are set and the widget dimension is not a fixed dimension. By default, if a widget is set to WRAP_CONTENT, we will treat that dimension as a fixed dimension, meaning the dimension will not change regardless of constraints. Setting this attribute to true allows the dimension to change in order to respect constraints.

constraintTag

public String constraintTag

Define a category of view to be used by helpers and motionLayout

dimensionRatio

public String dimensionRatio

The ratio information.

editorAbsoluteX

public int editorAbsoluteX

The design time location of the left side of the child. Used at design time for a horizontally unconstrained child.

editorAbsoluteY

public int editorAbsoluteY

The design time location of the right side of the child. Used at design time for a vertically unconstrained child.

endToEnd

public int endToEnd

Constrains the end side of a child to the end side of a target child (contains the target child id).

endToStart

public int endToStart

Constrains the end side of a child to the start side of a target child (contains the target child id).

goneBaselineMargin

public int goneBaselineMargin

The baseline margin to use when the target is gone.

goneBottomMargin

public int goneBottomMargin

The bottom margin to use when the target is gone.

goneEndMargin

public int goneEndMargin

The end margin to use when the target is gone.

goneLeftMargin

public int goneLeftMargin

The left margin to use when the target is gone.

goneRightMargin

public int goneRightMargin

The right margin to use when the target is gone

goneStartMargin

public int goneStartMargin

The start margin to use when the target is gone.

goneTopMargin

public int goneTopMargin

The top margin to use when the target is gone.

guideBegin

public int guideBegin

The distance of child (guideline) to the top or left edge of its parent.

guideEnd

public int guideEnd

The distance of child (guideline) to the top or left edge of its parent.

guidePercent

public float guidePercent

The ratio of the distance to the parent's sides

helped

public boolean helped

horizontalBias

public float horizontalBias

The ratio between two connections when the left and right (or start and end) sides are constrained.

horizontalChainStyle

public int horizontalChainStyle

If the child is the start of a horizontal chain, this attribute will drive how the elements of the chain will be positioned. 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

horizontalWeight

public float horizontalWeight

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

leftToLeft

public int leftToLeft

Constrains the left side of a child to the left side of a target child (contains the target child id).

leftToRight

public int leftToRight

Constrains the left side of a child to the right side of a target child (contains the target child id).

matchConstraintDefaultHeight

public int matchConstraintDefaultHeight

Define how the widget vertical dimension is handled when set to MATCH_CONSTRAINT

  • MATCH_CONSTRAINT_SPREAD -- the default. The dimension will expand up to the constraints, minus margins
  • MATCH_CONSTRAINT_WRAP -- DEPRECATED -- use instead WRAP_CONTENT and constrainedWidth=true
    The dimension will be the same as WRAP_CONTENT, unless the size ends up too large for the constraints; in that case the dimension will expand up to the constraints, minus margins
  • This attribute may not be applied if the widget is part of a chain in that dimension.
  • MATCH_CONSTRAINT_PERCENT -- The dimension will be a percent of another widget (by default, the parent)

matchConstraintDefaultWidth

public int matchConstraintDefaultWidth

Define how the widget horizontal dimension is handled when set to MATCH_CONSTRAINT

  • MATCH_CONSTRAINT_SPREAD -- the default. The dimension will expand up to the constraints, minus margins
  • MATCH_CONSTRAINT_WRAP -- DEPRECATED -- use instead WRAP_CONTENT and constrainedWidth=true
    The dimension will be the same as WRAP_CONTENT, unless the size ends up too large for the constraints; in that case the dimension will expand up to the constraints, minus margins
  • This attribute may not be applied if the widget is part of a chain in that dimension.
  • MATCH_CONSTRAINT_PERCENT -- The dimension will be a percent of another widget (by default, the parent)

matchConstraintMaxHeight

public int matchConstraintMaxHeight

Specify a maximum height size for the widget. It will only apply if the size of the widget is set to MATCH_CONSTRAINT. Don't apply if the widget is part of a vertical chain.

matchConstraintMaxWidth

public int matchConstraintMaxWidth

Specify a maximum width size for the widget. It will only apply if the size of the widget is set to MATCH_CONSTRAINT. Don't apply if the widget is part of a horizontal chain.

matchConstraintMinHeight

public int matchConstraintMinHeight

Specify a minimum height size for the widget. It will only apply if the size of the widget is set to MATCH_CONSTRAINT. Don't apply if the widget is part of a vertical chain.

matchConstraintMinWidth

public int matchConstraintMinWidth

Specify a minimum width size for the widget. It will only apply if the size of the widget is set to MATCH_CONSTRAINT. Don't apply if the widget is part of a horizontal chain.

matchConstraintPercentHeight

public float matchConstraintPercentHeight

Specify the percentage when using the match constraint percent mode. From 0 to 1.

matchConstraintPercentWidth

public float matchConstraintPercentWidth

Specify the percentage when using the match constraint percent mode. From 0 to 1.

orientation

public int orientation

rightToLeft

public int rightToLeft

Constrains the right side of a child to the left side of a target child (contains the target child id).

rightToRight

public int rightToRight

Constrains the right side of a child to the right side of a target child (contains the target child id).

startToEnd

public int startToEnd

Constrains the start side of a child to the end side of a target child (contains the target child id).

startToStart

public int startToStart

Constrains the start side of a child to the start side of a target child (contains the target child id).

topToBottom

public int topToBottom

Constrains the top side of a child to the bottom side of a target child (contains the target child id).

topToTop

public int topToTop

Constrains the top side of a child to the top side of a target child (contains the target child id).

verticalBias

public float verticalBias

The ratio between two connections when the top and bottom sides are constrained.

verticalChainStyle

public int verticalChainStyle

If the child is the start of a vertical chain, this attribute will drive how the elements of the chain will be positioned. 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 vertical bias attribute of the child will then affect the positioning of the packed elements

verticalWeight

public float verticalWeight

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

wrapBehaviorInParent

public int wrapBehaviorInParent

Specify how this view is taken in account during the parent's wrap computation Can be either of: WRAP_BEHAVIOR_INCLUDED the widget is taken in account for the wrap (default) WRAP_BEHAVIOR_HORIZONTAL_ONLY the widget will be included in the wrap only horizontally WRAP_BEHAVIOR_VERTICAL_ONLY the widget will be included in the wrap only vertically WRAP_BEHAVIOR_SKIPPED the widget is not part of the wrap computation

Public constructors

LayoutParams

public LayoutParams (ConstraintLayout.LayoutParams source)

Create a LayoutParams base on an existing layout Params

Parameters
source ConstraintLayout.LayoutParams: the Layout Params to be copied

LayoutParams

public LayoutParams (Context c, 
                AttributeSet attrs)

Parameters
c Context

attrs AttributeSet

LayoutParams

public LayoutParams (int width, 
                int height)

Parameters
width int

height int

LayoutParams

public LayoutParams (ViewGroup.LayoutParams source)

Parameters
source ViewGroup.LayoutParams

Public methods

getConstraintTag

public String getConstraintTag ()

Tag that can be used to identify a view as being a member of a group. Which can be used for Helpers or in MotionLayout

Returns
String tag string or null if not defined

reset

public void reset ()

resolveLayoutDirection

public void resolveLayoutDirection (int layoutDirection)

Parameters
layoutDirection int

validate

public void validate ()