ConstraintLayout.LayoutParams

public class ConstraintLayout.LayoutParams extends ViewGroup.MarginLayoutParams


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

static final int

The baseline of the text in a view.

static final int
BOTTOM = 4

The bottom side of a view.

static final int

Chain packed style

static final int

Chain spread style

static final int

Chain spread inside style

static final int
CIRCLE = 8

Circle reference from a view.

static final int
END = 7

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

static final int
GONE_UNSET = -2147483648

Defines an id that is not set.

static final int

The horizontal orientation.

static final int
LEFT = 1

The left side of a view.

static final int

Dimension will be controlled by constraints.

static final int

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

static final int

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

static final int

Set matchConstraintDefault* default to the wrap content size.

static final int

References the id of the parent.

static final int
RIGHT = 2

The right side of a view.

static final int
START = 6

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

static final int
TOP = 3

The top of a view.

static final int
UNSET = -1

Defines an id that is not set.

static final int

The vertical orientation.

static final int
static final int
static final int
static final int

Public fields

int

The baseline margin.

int

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

int

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

int

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

int

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

int

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

float

The angle used for a circular constraint]

int

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

int

The radius used for a circular constraint

boolean

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

boolean

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

String

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

String

The ratio information.

int

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

int

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

int

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

int

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

int

The baseline margin to use when the target is gone.

int

The bottom margin to use when the target is gone.

int

The end margin to use when the target is gone.

int

The left margin to use when the target is gone.

int

The right margin to use when the target is gone

int

The start margin to use when the target is gone.

int

The top margin to use when the target is gone.

int

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

int

The distance of child (guideline) to the bottom or right edge of its parent.

float

The ratio of the distance to the parent's sides

boolean

The ratio of the distance to the parent's sides

boolean
float

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

int

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

float

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

int

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

int

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

int

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

int

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

int

Specify a maximum height size for the widget.

int

Specify a maximum width size for the widget.

int

Specify a minimum height size for the widget.

int

Specify a minimum width size for the widget.

float

Specify the percentage when using the match constraint percent mode.

float

Specify the percentage when using the match constraint percent mode.

int
int

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

int

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

int

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

int

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

int

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

int

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

float

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

int

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

float

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

int

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

Create a LayoutParams base on an existing layout Params

LayoutParams(int width, int height)

Public methods

String

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

ConstraintWidget
void

Reset the ConstraintWidget

void
@TargetApi(value = Build.VERSION_CODES.JELLY_BEAN_MR1)
resolveLayoutDirection(int layoutDirection)
void
void

validate the layout

Inherited Constants

From android.view.ViewGroup.LayoutParams
static final int

This field is deprecated.

static final int
static final int

Inherited methods

From android.view.ViewGroup.LayoutParams
void
setBaseAttributes(TypedArray a, int widthAttr, int heightAttr)
From android.view.ViewGroup.MarginLayoutParams
int
int
int
boolean
void
setLayoutDirection(int layoutDirection)
void
setMarginEnd(int end)
void
setMarginStart(int start)
void
setMargins(int left, int top, int right, int bottom)

Constants

BASELINE

Added in 2.2.0-alpha13
public static final int BASELINE = 5

The baseline of the text in a view.

BOTTOM

Added in 2.2.0-alpha13
public static final int BOTTOM = 4

The bottom side of a view.

CHAIN_PACKED

Added in 2.2.0-alpha13
public static final int CHAIN_PACKED = 2

Chain packed style

CHAIN_SPREAD

Added in 2.2.0-alpha13
public static final int CHAIN_SPREAD = 0

Chain spread style

CHAIN_SPREAD_INSIDE

Added in 2.2.0-alpha13
public static final int CHAIN_SPREAD_INSIDE = 1

Chain spread inside style

CIRCLE

Added in 2.2.0-alpha13
public static final int CIRCLE = 8

Circle reference from a view.

END

Added in 2.2.0-alpha13
public static final int END = 7

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

GONE_UNSET

Added in 2.2.0-alpha13
public static final int GONE_UNSET = -2147483648

Defines an id that is not set.

HORIZONTAL

Added in 2.2.0-alpha13
public static final int HORIZONTAL = 0

The horizontal orientation.

LEFT

Added in 2.2.0-alpha13
public static final int LEFT = 1

The left side of a view.

MATCH_CONSTRAINT

Added in 2.2.0-alpha13
public static final int MATCH_CONSTRAINT = 0

Dimension will be controlled by constraints.

MATCH_CONSTRAINT_PERCENT

Added in 2.2.0-alpha13
public static final int MATCH_CONSTRAINT_PERCENT = 2

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

MATCH_CONSTRAINT_SPREAD

Added in 2.2.0-alpha13
public static final int MATCH_CONSTRAINT_SPREAD = 0

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

MATCH_CONSTRAINT_WRAP

Added in 2.2.0-alpha13
public static final int MATCH_CONSTRAINT_WRAP = 1

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

PARENT_ID

Added in 2.2.0-alpha13
public static final int PARENT_ID = 0

References the id of the parent.

RIGHT

Added in 2.2.0-alpha13
public static final int RIGHT = 2

The right side of a view.

START

Added in 2.2.0-alpha13
public static final int START = 6

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
public static final int TOP = 3

The top of a view.

UNSET

Added in 2.2.0-alpha13
public static final int UNSET = -1

Defines an id that is not set.

VERTICAL

Added in 2.2.0-alpha13
public static final int VERTICAL = 1

The vertical orientation.

WRAP_BEHAVIOR_HORIZONTAL_ONLY

Added in 2.2.0-alpha13
public static final int WRAP_BEHAVIOR_HORIZONTAL_ONLY = 1

WRAP_BEHAVIOR_INCLUDED

Added in 2.2.0-alpha13
public static final int WRAP_BEHAVIOR_INCLUDED = 0

WRAP_BEHAVIOR_SKIPPED

Added in 2.2.0-alpha13
public static final int WRAP_BEHAVIOR_SKIPPED = 3

WRAP_BEHAVIOR_VERTICAL_ONLY

Added in 2.2.0-alpha13
public static final int WRAP_BEHAVIOR_VERTICAL_ONLY = 2

Public fields

baselineMargin

Added in 2.2.0-alpha13
public int baselineMargin

The baseline margin.

baselineToBaseline

Added in 2.2.0-alpha13
public int baselineToBaseline

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

baselineToBottom

Added in 2.2.0-alpha13
public int baselineToBottom

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

baselineToTop

Added in 2.2.0-alpha13
public int baselineToTop

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

bottomToBottom

Added in 2.2.0-alpha13
public int bottomToBottom

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

bottomToTop

Added in 2.2.0-alpha13
public int bottomToTop

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

circleAngle

Added in 2.2.0-alpha13
public float circleAngle

The angle used for a circular constraint]

circleConstraint

Added in 2.2.0-alpha13
public int circleConstraint

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

circleRadius

Added in 2.2.0-alpha13
public int circleRadius

The radius used for a circular constraint

constrainedHeight

Added in 2.2.0-alpha13
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

Added in 2.2.0-alpha13
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

Added in 2.2.0-alpha13
public String constraintTag

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

dimensionRatio

Added in 2.2.0-alpha13
public String dimensionRatio

The ratio information.

editorAbsoluteX

Added in 2.2.0-alpha13
public int editorAbsoluteX

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

editorAbsoluteY

Added in 2.2.0-alpha13
public int editorAbsoluteY

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

endToEnd

Added in 2.2.0-alpha13
public int endToEnd

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

endToStart

Added in 2.2.0-alpha13
public int endToStart

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

goneBaselineMargin

Added in 2.2.0-alpha13
public int goneBaselineMargin

The baseline margin to use when the target is gone.

goneBottomMargin

Added in 2.2.0-alpha13
public int goneBottomMargin

The bottom margin to use when the target is gone.

goneEndMargin

Added in 2.2.0-alpha13
public int goneEndMargin

The end margin to use when the target is gone.

goneLeftMargin

Added in 2.2.0-alpha13
public int goneLeftMargin

The left margin to use when the target is gone.

goneRightMargin

Added in 2.2.0-alpha13
public int goneRightMargin

The right margin to use when the target is gone

goneStartMargin

Added in 2.2.0-alpha13
public int goneStartMargin

The start margin to use when the target is gone.

goneTopMargin

Added in 2.2.0-alpha13
public int goneTopMargin

The top margin to use when the target is gone.

guideBegin

Added in 2.2.0-alpha13
public int guideBegin

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

guideEnd

Added in 2.2.0-alpha13
public int guideEnd

The distance of child (guideline) to the bottom or right edge of its parent.

guidePercent

Added in 2.2.0-alpha13
public float guidePercent

The ratio of the distance to the parent's sides

guidelineUseRtl

Added in 2.2.0-alpha13
public boolean guidelineUseRtl

The ratio of the distance to the parent's sides

helped

Added in 2.2.0-alpha13
public boolean helped

horizontalBias

Added in 2.2.0-alpha13
public float horizontalBias

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

horizontalChainStyle

Added in 2.2.0-alpha13
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

Added in 2.2.0-alpha13
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

Added in 2.2.0-alpha13
public int leftToLeft

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

leftToRight

Added in 2.2.0-alpha13
public int leftToRight

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

matchConstraintDefaultHeight

Added in 2.2.0-alpha13
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

Added in 2.2.0-alpha13
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

Added in 2.2.0-alpha13
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

Added in 2.2.0-alpha13
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

Added in 2.2.0-alpha13
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

Added in 2.2.0-alpha13
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

Added in 2.2.0-alpha13
public float matchConstraintPercentHeight

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

matchConstraintPercentWidth

Added in 2.2.0-alpha13
public float matchConstraintPercentWidth

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

orientation

Added in 2.2.0-alpha13
public int orientation

rightToLeft

Added in 2.2.0-alpha13
public int rightToLeft

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

rightToRight

Added in 2.2.0-alpha13
public int rightToRight

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

startToEnd

Added in 2.2.0-alpha13
public int startToEnd

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

startToStart

Added in 2.2.0-alpha13
public int startToStart

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

topToBottom

Added in 2.2.0-alpha13
public int topToBottom

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

topToTop

Added in 2.2.0-alpha13
public int topToTop

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

verticalBias

Added in 2.2.0-alpha13
public float verticalBias

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

verticalChainStyle

Added in 2.2.0-alpha13
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

Added in 2.2.0-alpha13
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

Added in 2.2.0-alpha13
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

Added in 2.2.0-alpha13
public LayoutParams(ViewGroup.LayoutParams params)

Create a LayoutParams base on an existing layout Params

Parameters
ViewGroup.LayoutParams params

the Layout Params to be copied

LayoutParams

Added in 2.2.0-alpha13
public LayoutParams(Context c, AttributeSet attrs)

LayoutParams

Added in 2.2.0-alpha13
public LayoutParams(int width, int height)

Public methods

getConstraintTag

Added in 2.2.0-alpha13
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

getConstraintWidget

Added in 2.2.0-alpha13
public ConstraintWidget getConstraintWidget()

reset

Added in 2.2.0-alpha13
public void reset()

Reset the ConstraintWidget

resolveLayoutDirection

@TargetApi(value = Build.VERSION_CODES.JELLY_BEAN_MR1)
public void resolveLayoutDirection(int layoutDirection)

setWidgetDebugName

Added in 2.2.0-alpha13
public void setWidgetDebugName(String text)
Parameters
String text

validate

Added in 2.2.0-alpha13
public void validate()

validate the layout