ConstraintSet

public class ConstraintSet


This class allows you to define programmatically a set of constraints to be used with ConstraintLayout.

For details about Constraint behaviour see ConstraintLayout. It lets you create and save constraints, and apply them to an existing ConstraintLayout. ConstraintsSet can be created in various ways:

  • Manually {@code c = new ConstraintSet(); c.connect(....);}
  • from a R.layout.* object {@code c.clone(context, R.layout.layout1);}
  • from a ConstraintLayout {@code c.clone(constraintLayout);}
Example code:
import android.content.Context;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.constraint.ConstraintSet;
import android.support.transition.TransitionManager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

public class MainActivity extends AppCompatActivity {
    ConstraintSet mConstraintSet1 = new ConstraintSet(); // create a Constraint Set
    ConstraintSet mConstraintSet2 = new ConstraintSet(); // create a Constraint Set
    ConstraintLayout mConstraintLayout; // cache the ConstraintLayout
    boolean mOld = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Context context = this;
        mConstraintSet2.clone(context, R.layout.state2); // get constraints from layout
        setContentView(R.layout.state1);
        mConstraintLayout = (ConstraintLayout) findViewById(R.id.activity_main);
        mConstraintSet1.clone(mConstraintLayout); // get constraints from ConstraintSet
    }

    public void foo(View view) {
        TransitionManager.beginDelayedTransition(mConstraintLayout);
        if (mOld = !mOld) {
            mConstraintSet1.applyTo(mConstraintLayout); // set new constraints
        }  else {
            mConstraintSet2.applyTo(mConstraintLayout); // set new constraints
        }
    }
}

Summary

Constants

static final @NonNull int

The baseline of the text in a view.

static final @NonNull int

The bottom side of a view.

static final @NonNull int

Chain packed style

static final @NonNull int

Chain spread style

static final @NonNull int

Chain spread inside style

static final @NonNull int

Circle reference from a view.

static final @NonNull int

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

static final @NonNull int

This view is gone, and will not take any space for layout purposes.

static final @NonNull int

The horizontal orientation.

static final @NonNull int

Used to create a horizontal create guidelines.

static final @NonNull int

This view is invisible, but it still takes up space for layout purposes.

static final @NonNull int

The left side of a view.

static final @NonNull int

Dimension will be controlled by constraints

static final @NonNull int
static final @NonNull int

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

static final @NonNull int

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

static final @NonNull int

References the id of the parent.

static final @NonNull int

The right side of a view.

static final @NonNull int
static final @NonNull int
static final @NonNull int
static final @NonNull int
static final @NonNull int
static final @NonNull int

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

static final @NonNull int

The top of a view.

static final @NonNull int

Used to indicate a parameter is cleared or not set

static final @NonNull int

The vertical orientation.

static final @NonNull int

Used to create a vertical create guidelines.

static final @NonNull int
static final @NonNull int
static final @NonNull int

This view is visible.

static final @NonNull int

Dimension will set by the view's content

Public methods

@NonNull void
@NonNull void
@NonNull void
@NonNull void
@NonNull void
addToHorizontalChain(
    @NonNull int viewId,
    @NonNull int leftId,
    @NonNull int rightId
)

Adds a view to a horizontal chain.

@NonNull void
addToHorizontalChainRTL(
    @NonNull int viewId,
    @NonNull int leftId,
    @NonNull int rightId
)

Adds a view to a horizontal chain.

@NonNull void
addToVerticalChain(
    @NonNull int viewId,
    @NonNull int topId,
    @NonNull int bottomId
)

Adds a view to a vertical chain.

@NonNull void

Apply custom attributes alone

@NonNull void
@NonNull void
applyTo(@NonNull ConstraintLayout constraintLayout)

Apply the constraints to a ConstraintLayout.

@NonNull void
applyToHelper(
    @NonNull ConstraintHelper helper,
    @NonNull ConstraintWidget child,
    @NonNull ConstraintLayout.LayoutParams layoutParams,
    @NonNull SparseArray<@NonNull ConstraintWidget> mapIdToWidget
)

Apply Layout to Helper widget

@NonNull void
applyToLayoutParams(
    @NonNull int id,
    @NonNull ConstraintLayout.LayoutParams layoutParams
)

Fill in a ConstraintLayout LayoutParam based on the id.

@NonNull void

Apply the constraints to a ConstraintLayout.

static @NonNull ConstraintSet.Constraint

Used to read a ConstraintDelta

@NonNull void
center(
    @NonNull int centerID,
    @NonNull int firstID,
    @NonNull int firstSide,
    @NonNull int firstMargin,
    @NonNull int secondId,
    @NonNull int secondSide,
    @NonNull int secondMargin,
    @NonNull float bias
)

Center widget between the other two widgets.

@NonNull void
centerHorizontally(
    @NonNull int centerID,
    @NonNull int leftId,
    @NonNull int leftSide,
    @NonNull int leftMargin,
    @NonNull int rightId,
    @NonNull int rightSide,
    @NonNull int rightMargin,
    @NonNull float bias
)

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

@NonNull void
centerHorizontally(@NonNull int viewId, @NonNull int toView)

Centers the view horizontally relative to toView's position.

@NonNull void
centerHorizontallyRtl(
    @NonNull int centerID,
    @NonNull int startId,
    @NonNull int startSide,
    @NonNull int startMargin,
    @NonNull int endId,
    @NonNull int endSide,
    @NonNull int endMargin,
    @NonNull float bias
)

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

@NonNull void
centerHorizontallyRtl(@NonNull int viewId, @NonNull int toView)

Centers the view horizontally relative to toView's position.

@NonNull void
centerVertically(
    @NonNull int centerID,
    @NonNull int topId,
    @NonNull int topSide,
    @NonNull int topMargin,
    @NonNull int bottomId,
    @NonNull int bottomSide,
    @NonNull int bottomMargin,
    @NonNull float bias
)

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

@NonNull void
centerVertically(@NonNull int viewId, @NonNull int toView)

Centers the view vertically relative to toView's position.

@NonNull void
clear(@NonNull int viewId)

Remove all constraints from this view.

@NonNull void
clear(@NonNull int viewId, @NonNull int anchor)

Remove a constraint from this view.

@NonNull void
clone(@NonNull Context context, @NonNull int constraintLayoutId)

Copy the constraints from a layout.

@NonNull void

Copy the constraints from a layout.

@NonNull void
clone(@NonNull ConstraintLayout constraintLayout)

Copy the layout parameters of a ConstraintLayout.

@NonNull void
clone(@NonNull Constraints constraints)

Copy the layout parameters of a ConstraintLayout.

@NonNull void
connect(
    @NonNull int startID,
    @NonNull int startSide,
    @NonNull int endID,
    @NonNull int endSide,
    @NonNull int margin
)

Create a constraint between two widgets.

@NonNull void
connect(
    @NonNull int startID,
    @NonNull int startSide,
    @NonNull int endID,
    @NonNull int endSide
)

Create a constraint between two widgets.

@NonNull void
constrainCircle(
    @NonNull int viewId,
    @NonNull int id,
    @NonNull int radius,
    @NonNull float angle
)

Constrain the view on a circle constraint

@NonNull void
constrainDefaultHeight(@NonNull int viewId, @NonNull int height)

Sets how the height is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD.

@NonNull void
constrainDefaultWidth(@NonNull int viewId, @NonNull int width)

Sets how the width is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD.

@NonNull void
constrainHeight(@NonNull int viewId, @NonNull int height)

Sets the height of the view.

@NonNull void
constrainMaxHeight(@NonNull int viewId, @NonNull int height)

Sets the maximum height of the view.

@NonNull void
constrainMaxWidth(@NonNull int viewId, @NonNull int width)

Sets the maximum width of the view.

@NonNull void
constrainMinHeight(@NonNull int viewId, @NonNull int height)

Sets the height of the view.

@NonNull void
constrainMinWidth(@NonNull int viewId, @NonNull int width)

Sets the width of the view.

@NonNull void
constrainPercentHeight(@NonNull int viewId, @NonNull float percent)

Sets the height of the view as a percentage of the parent.

@NonNull void
constrainPercentWidth(@NonNull int viewId, @NonNull float percent)

Sets the width of the view as a percentage of the parent.

@NonNull void
constrainWidth(@NonNull int viewId, @NonNull int width)

Sets the width of the view.

@NonNull void
constrainedHeight(@NonNull int viewId, @NonNull boolean constrained)

Sets how the height is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD.

@NonNull void
constrainedWidth(@NonNull int viewId, @NonNull boolean constrained)

Sets how the width is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD.

@NonNull void
create(@NonNull int guidelineID, @NonNull int orientation)

Creates a ConstraintLayout virtual object.

@NonNull void
createBarrier(
    @NonNull int id,
    @NonNull int direction,
    @NonNull int margin,
    @NonNull Array<@NonNull int> referenced
)

Creates a ConstraintLayout Barrier object.

@NonNull void
createHorizontalChain(
    @NonNull int leftId,
    @NonNull int leftSide,
    @NonNull int rightId,
    @NonNull int rightSide,
    @NonNull Array<@NonNull int> chainIds,
    @NonNull Array<@NonNull float> weights,
    @NonNull int style
)

Spaces a set of widgets horizontally between the view startID and endId.

@NonNull void
createHorizontalChainRtl(
    @NonNull int startId,
    @NonNull int startSide,
    @NonNull int endId,
    @NonNull int endSide,
    @NonNull Array<@NonNull int> chainIds,
    @NonNull Array<@NonNull float> weights,
    @NonNull int style
)

Spaces a set of widgets horizontal between the view startID and endId.

@NonNull void
createVerticalChain(
    @NonNull int topId,
    @NonNull int topSide,
    @NonNull int bottomId,
    @NonNull int bottomSide,
    @NonNull Array<@NonNull int> chainIds,
    @NonNull Array<@NonNull float> weights,
    @NonNull int style
)

Spaces a set of widgets vertically between the view topId and bottomId.

@NonNull void
dump(@NonNull MotionScene scene, @NonNull Array<@NonNull int> ids)

Dump the contents

@NonNull boolean

return with the constraint set will apply elevation for the specified view.

@NonNull ConstraintSet.Constraint
@NonNull HashMap<@NonNull String, @NonNull ConstraintAttribute>
@NonNull int
getHeight(@NonNull int viewId)

Get the height set in the view

@NonNull Array<@NonNull int>
@NonNull ConstraintSet.Constraint
@NonNull Array<@NonNull int>

get the reference id's of a helper.

@NonNull int
getVisibility(@NonNull int viewId)

Get the visibility flag set in this view

@NonNull int

ConstraintSet will not setVisibility.

@NonNull int
getWidth(@NonNull int viewId)

Get the width set in the view

@NonNull boolean

Enforce id are required for all ConstraintLayout children to use ConstraintSet.

@NonNull void
load(@NonNull Context context, @NonNull int resourceId)

Load a constraint set from a constraintSet.xml file.

@NonNull void
load(@NonNull Context context, @NonNull XmlPullParser parser)

Load a constraint set from a constraintSet.xml file

@NonNull void
@NonNull void
@NonNull void
@NonNull void
@NonNull void

This will copy Constraints from the ConstraintSet

@NonNull void

This will copy Constraints from the ConstraintLayout if it does not have parameters

@NonNull void
removeAttribute(@NonNull String attributeName)
@NonNull void

Removes a view from a horizontal chain.

@NonNull void

Removes a view from a vertical chain.

@NonNull void
setAlpha(@NonNull int viewId, @NonNull float alpha)

Adjust the alpha of a view.

@NonNull void
setApplyElevation(@NonNull int viewId, @NonNull boolean apply)

set if elevation will be applied to the view.

@NonNull void
setBarrierType(@NonNull int id, @NonNull int type)
@NonNull void
setColorValue(
    @NonNull int viewId,
    @NonNull String attributeName,
    @NonNull int value
)
@NonNull void
setDimensionRatio(@NonNull int viewId, @NonNull String ratio)

Constrains the views aspect ratio.

@NonNull void
setEditorAbsoluteX(@NonNull int viewId, @NonNull int position)
@NonNull void
setEditorAbsoluteY(@NonNull int viewId, @NonNull int position)
@NonNull void
setElevation(@NonNull int viewId, @NonNull float elevation)

Adjust the elevation of a view.

@NonNull void
setFloatValue(
    @NonNull int viewId,
    @NonNull String attributeName,
    @NonNull float value
)
@NonNull void
setForceId(@NonNull boolean forceId)

Enforce id are required for all ConstraintLayout children to use ConstraintSet.

@NonNull void
setGoneMargin(@NonNull int viewId, @NonNull int anchor, @NonNull int value)

Sets the gone margin.

@NonNull void
setGuidelineBegin(@NonNull int guidelineID, @NonNull int margin)

Set the guideline's distance form the top or left edge.

@NonNull void
setGuidelineEnd(@NonNull int guidelineID, @NonNull int margin)

Set a guideline's distance to end.

@NonNull void
setGuidelinePercent(@NonNull int guidelineID, @NonNull float ratio)

Set a Guideline's percent.

@NonNull void
setHorizontalBias(@NonNull int viewId, @NonNull float bias)

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

@NonNull void
setHorizontalChainStyle(@NonNull int viewId, @NonNull int chainStyle)

How the elements of the horizontal chain will be positioned.

@NonNull void
setHorizontalWeight(@NonNull int viewId, @NonNull float weight)

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

@NonNull void
setIntValue(
    @NonNull int viewId,
    @NonNull String attributeName,
    @NonNull int value
)
@NonNull void
setLayoutWrapBehavior(@NonNull int viewId, @NonNull int behavior)

Sets the wrap behavior of the widget in the parent's wrap computation

@NonNull void
setMargin(@NonNull int viewId, @NonNull int anchor, @NonNull int value)

Sets the margin.

@NonNull void
setReferencedIds(@NonNull int id, @NonNull Array<@NonNull int> referenced)

sets the reference id's of a barrier.

@NonNull void
setRotation(@NonNull int viewId, @NonNull float rotation)

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

@NonNull void
setRotationX(@NonNull int viewId, @NonNull float rotationX)

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

@NonNull void
setRotationY(@NonNull int viewId, @NonNull float rotationY)

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

@NonNull void
setScaleX(@NonNull int viewId, @NonNull float scaleX)

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

@NonNull void
setScaleY(@NonNull int viewId, @NonNull float scaleY)

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

@NonNull void
setStringValue(
    @NonNull int viewId,
    @NonNull String attributeName,
    @NonNull String value
)
@NonNull void
setTransformPivot(
    @NonNull int viewId,
    @NonNull float transformPivotX,
    @NonNull float transformPivotY
)

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

@NonNull void
setTransformPivotX(@NonNull int viewId, @NonNull float transformPivotX)

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

@NonNull void
setTransformPivotY(@NonNull int viewId, @NonNull float transformPivotY)

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

@NonNull void
setTranslation(
    @NonNull int viewId,
    @NonNull float translationX,
    @NonNull float translationY
)

Adjust the post-layout translation of a view.

@NonNull void
setTranslationX(@NonNull int viewId, @NonNull float translationX)

Adjust the post-layout X translation of a view.

@NonNull void
setTranslationY(@NonNull int viewId, @NonNull float translationY)

Adjust the post-layout Y translation of a view.

@NonNull void
setTranslationZ(@NonNull int viewId, @NonNull float translationZ)

Adjust the translation in Z of a view.

@NonNull void
setValidateOnParse(@NonNull boolean validate)

If true perform validation checks when parsing ConstraintSets This will slow down parsing and should only be used for debugging

@NonNull void
setVerticalBias(@NonNull int viewId, @NonNull float bias)

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

@NonNull void
setVerticalChainStyle(@NonNull int viewId, @NonNull int chainStyle)

How the elements of the vertical chain will be positioned.

@NonNull void
setVerticalWeight(@NonNull int viewId, @NonNull float weight)

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

@NonNull void
setVisibility(@NonNull int viewId, @NonNull int visibility)

Adjust the visibility of a view.

@NonNull void
setVisibilityMode(@NonNull int viewId, @NonNull int visibilityMode)

ConstraintSet will not setVisibility.

@NonNull void
writeState(
    @NonNull Writer writer,
    @NonNull ConstraintLayout layout,
    @NonNull int flags
)

Constants

BASELINE

@NonNull
public static final @NonNull int BASELINE

The baseline of the text in a view.

BOTTOM

@NonNull
public static final @NonNull int BOTTOM

The bottom side of a view.

CHAIN_PACKED

@NonNull
public static final @NonNull int CHAIN_PACKED

Chain packed style

CHAIN_SPREAD

@NonNull
public static final @NonNull int CHAIN_SPREAD

Chain spread style

CHAIN_SPREAD_INSIDE

@NonNull
public static final @NonNull int CHAIN_SPREAD_INSIDE

Chain spread inside style

CIRCLE_REFERENCE

@NonNull
public static final @NonNull int CIRCLE_REFERENCE

Circle reference from a view.

END

@NonNull
public static final @NonNull 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

GONE

@NonNull
public static final @NonNull int GONE

This view is gone, and will not take any space for layout purposes. Use with setVisibility and {@code * android:visibility}.

HORIZONTAL

@NonNull
public static final @NonNull int HORIZONTAL

The horizontal orientation.

HORIZONTAL_GUIDELINE

@NonNull
public static final @NonNull int HORIZONTAL_GUIDELINE

Used to create a horizontal create guidelines.

INVISIBLE

@NonNull
public static final @NonNull int INVISIBLE

This view is invisible, but it still takes up space for layout purposes. Use with setVisibility and {@code * android:visibility}.

LEFT

@NonNull
public static final @NonNull int LEFT

The left side of a view.

MATCH_CONSTRAINT

@NonNull
public static final @NonNull int MATCH_CONSTRAINT

Dimension will be controlled by constraints

MATCH_CONSTRAINT_PERCENT

@NonNull
public static final @NonNull int MATCH_CONSTRAINT_PERCENT

MATCH_CONSTRAINT_SPREAD

@NonNull
public static final @NonNull int MATCH_CONSTRAINT_SPREAD

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

MATCH_CONSTRAINT_WRAP

@NonNull
public static final @NonNull int MATCH_CONSTRAINT_WRAP

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

PARENT_ID

@NonNull
public static final @NonNull int PARENT_ID

References the id of the parent. Used in:

RIGHT

@NonNull
public static final @NonNull int RIGHT

The right side of a view.

ROTATE_LEFT_OF_PORTRATE

@NonNull
public static final @NonNull int ROTATE_LEFT_OF_PORTRATE

ROTATE_NONE

@NonNull
public static final @NonNull int ROTATE_NONE

ROTATE_PORTRATE_OF_LEFT

@NonNull
public static final @NonNull int ROTATE_PORTRATE_OF_LEFT

ROTATE_PORTRATE_OF_RIGHT

@NonNull
public static final @NonNull int ROTATE_PORTRATE_OF_RIGHT

ROTATE_RIGHT_OF_PORTRATE

@NonNull
public static final @NonNull int ROTATE_RIGHT_OF_PORTRATE

START

@NonNull
public static final @NonNull 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

TOP

@NonNull
public static final @NonNull int TOP

The top of a view.

UNSET

@NonNull
public static final @NonNull int UNSET

Used to indicate a parameter is cleared or not set

VERTICAL

@NonNull
public static final @NonNull int VERTICAL

The vertical orientation.

VERTICAL_GUIDELINE

@NonNull
public static final @NonNull int VERTICAL_GUIDELINE

Used to create a vertical create guidelines. see create

VISIBILITY_MODE_IGNORE

@NonNull
public static final @NonNull int VISIBILITY_MODE_IGNORE

VISIBILITY_MODE_NORMAL

@NonNull
public static final @NonNull int VISIBILITY_MODE_NORMAL

VISIBLE

@NonNull
public static final @NonNull int VISIBLE

This view is visible. Use with setVisibility and {@code * android:visibility}.

WRAP_CONTENT

@NonNull
public static final @NonNull int WRAP_CONTENT

Dimension will set by the view's content

Public fields

derivedState

@NonNull
public @NonNull String derivedState

mIdString

@NonNull
public @NonNull String mIdString

mRotate

@NonNull
public @NonNull int mRotate

Public methods

addColorAttributes

@NonNull
public void addColorAttributes(@NonNull Array<@NonNull String> attributeName)

addFloatAttributes

@NonNull
public void addFloatAttributes(@NonNull Array<@NonNull String> attributeName)

addIntAttributes

@NonNull
public void addIntAttributes(@NonNull Array<@NonNull String> attributeName)

addStringAttributes

@NonNull
public void addStringAttributes(@NonNull Array<@NonNull String> attributeName)

addToHorizontalChain

@NonNull
public void addToHorizontalChain(
    @NonNull int viewId,
    @NonNull int leftId,
    @NonNull int rightId
)

Adds a view to a horizontal chain.

Parameters
@NonNull int viewId

view to add

@NonNull int leftId

view in chain to the left

@NonNull int rightId

view in chain to the right

addToHorizontalChainRTL

@NonNull
public void addToHorizontalChainRTL(
    @NonNull int viewId,
    @NonNull int leftId,
    @NonNull int rightId
)

Adds a view to a horizontal chain.

Parameters
@NonNull int viewId

view to add

@NonNull int leftId

view to the start side

@NonNull int rightId

view to the end side

addToVerticalChain

@NonNull
public void addToVerticalChain(
    @NonNull int viewId,
    @NonNull int topId,
    @NonNull int bottomId
)

Adds a view to a vertical chain.

Parameters
@NonNull int viewId

view to add to a vertical chain

@NonNull int topId

view above.

@NonNull int bottomId

view below

applyCustomAttributes

@NonNull
public void applyCustomAttributes(@NonNull ConstraintLayout constraintLayout)

Apply custom attributes alone

Parameters
@NonNull ConstraintLayout constraintLayout

applyDeltaFrom

@NonNull
public void applyDeltaFrom(@NonNull ConstraintSet cs)

applyTo

@NonNull
public void applyTo(@NonNull ConstraintLayout constraintLayout)

Apply the constraints to a ConstraintLayout.

Parameters
@NonNull ConstraintLayout constraintLayout

to be modified

applyToHelper

@NonNull
public void applyToHelper(
    @NonNull ConstraintHelper helper,
    @NonNull ConstraintWidget child,
    @NonNull ConstraintLayout.LayoutParams layoutParams,
    @NonNull SparseArray<@NonNull ConstraintWidget> mapIdToWidget
)

Apply Layout to Helper widget

applyToLayoutParams

@NonNull
public void applyToLayoutParams(
    @NonNull int id,
    @NonNull ConstraintLayout.LayoutParams layoutParams
)

Fill in a ConstraintLayout LayoutParam based on the id.

Parameters
@NonNull int id

Id of the view

@NonNull ConstraintLayout.LayoutParams layoutParams

LayoutParams to be filled

applyToWithoutCustom

@NonNull
public void applyToWithoutCustom(@NonNull ConstraintLayout constraintLayout)

Apply the constraints to a ConstraintLayout.

Parameters
@NonNull ConstraintLayout constraintLayout

to be modified

buildDelta

@NonNull
public static ConstraintSet.Constraint buildDelta(@NonNull Context context, @NonNull XmlPullParser parser)

Used to read a ConstraintDelta

Parameters
@NonNull Context context
@NonNull XmlPullParser parser

centerHorizontally

@NonNull
public void centerHorizontally(
    @NonNull int centerID,
    @NonNull int leftId,
    @NonNull int leftSide,
    @NonNull int leftMargin,
    @NonNull int rightId,
    @NonNull int rightSide,
    @NonNull int rightMargin,
    @NonNull float bias
)

Centers the widget horizontally to the left and right side on another widgets sides. (for sides see: { } , { { } ) ID of widget to be centered The Id of the widget on the left side The side of the leftId widget to connect to The margin on the left side The Id of the widget on the right side The side of the rightId widget to connect to The margin on the right side The ratio of the space on the left vs. right sides 0.5 is centered (default)

centerHorizontally

@NonNull
public void centerHorizontally(@NonNull int viewId, @NonNull int toView)

Centers the view horizontally relative to toView's position.

Parameters
@NonNull int viewId

ID of view to center Horizontally

@NonNull int toView

ID of view to center on (or in)

centerHorizontallyRtl

@NonNull
public void centerHorizontallyRtl(
    @NonNull int centerID,
    @NonNull int startId,
    @NonNull int startSide,
    @NonNull int startMargin,
    @NonNull int endId,
    @NonNull int endSide,
    @NonNull int endMargin,
    @NonNull float bias
)

Centers the widgets horizontally to the left and right side on another widgets sides. (for sides see: START, END, LEFT, RIGHT)

Parameters
@NonNull int centerID

ID of widget to be centered

@NonNull int startId

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

@NonNull int startSide

The side of the startId widget to connect to

@NonNull int startMargin

The margin on the start side

@NonNull int endId

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

@NonNull int endSide

The side of the endId widget to connect to

@NonNull int endMargin

The margin on the end side

@NonNull float bias

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

centerHorizontallyRtl

@NonNull
public void centerHorizontallyRtl(@NonNull int viewId, @NonNull int toView)

Centers the view horizontally relative to toView's position.

Parameters
@NonNull int viewId

ID of view to center Horizontally

@NonNull int toView

ID of view to center on (or in)

centerVertically

@NonNull
public void centerVertically(
    @NonNull int centerID,
    @NonNull int topId,
    @NonNull int topSide,
    @NonNull int topMargin,
    @NonNull int bottomId,
    @NonNull int bottomSide,
    @NonNull int bottomMargin,
    @NonNull float bias
)

Centers the widgets vertically to the top and bottom side on another widgets sides. (for sides see: { } ) ID of widget to be centered The Id of the widget on the top side The side of the leftId widget to connect to The margin on the top side The Id of the widget on the bottom side The side of the bottomId widget to connect to The margin on the bottom side The ratio of the space on the top vs. bottom sides 0.5 is centered (default)

centerVertically

@NonNull
public void centerVertically(@NonNull int viewId, @NonNull int toView)

Centers the view vertically relative to toView's position.

Parameters
@NonNull int viewId

ID of view to center Horizontally

@NonNull int toView

ID of view to center on (or in)

clear

@NonNull
public void clear(@NonNull int viewId)

Remove all constraints from this view.

Parameters
@NonNull int viewId

ID of view to remove all connections to

clear

@NonNull
public void clear(@NonNull int viewId, @NonNull int anchor)

Remove a constraint from this view.

Parameters
@NonNull int viewId

ID of view to center on (or in)

@NonNull int anchor

the Anchor to remove constraint from

clone

@NonNull
public void clone(@NonNull Context context, @NonNull int constraintLayoutId)

Copy the constraints from a layout.

Parameters
@NonNull Context context

the context for the layout inflation

@NonNull int constraintLayoutId

the id of the layout file

clone

@NonNull
public void clone(@NonNull ConstraintSet set)

Copy the constraints from a layout.

Parameters
@NonNull ConstraintSet set

constraint set to copy

clone

@NonNull
public void clone(@NonNull ConstraintLayout constraintLayout)

Copy the layout parameters of a ConstraintLayout.

Parameters
@NonNull ConstraintLayout constraintLayout

The ConstraintLayout to be copied

clone

@NonNull
public void clone(@NonNull Constraints constraints)

Copy the layout parameters of a ConstraintLayout.

Parameters
@NonNull Constraints constraints

The ConstraintLayout to be copied

connect

@NonNull
public void connect(
    @NonNull int startID,
    @NonNull int startSide,
    @NonNull int endID,
    @NonNull int endSide,
    @NonNull int margin
)

Create a constraint between two widgets. (for sides see: { } , { { } , { { } , { } ) the ID of the widget to be constrained the side of the widget to constrain the id of the widget to constrain to the side of widget to constrain to the margin to constrain (margin must be positive)

connect

@NonNull
public void connect(
    @NonNull int startID,
    @NonNull int startSide,
    @NonNull int endID,
    @NonNull int endSide
)

Create a constraint between two widgets. (for sides see: { } , { { } , { { } , { } ) the ID of the widget to be constrained the side of the widget to constrain the id of the widget to constrain to the side of widget to constrain to

constrainCircle

@NonNull
public void constrainCircle(
    @NonNull int viewId,
    @NonNull int id,
    @NonNull int radius,
    @NonNull float angle
)

Constrain the view on a circle constraint

Parameters
@NonNull int viewId

ID of the view we constrain

@NonNull int id

ID of the view we constrain relative to

@NonNull int radius

the radius of the circle in degrees

@NonNull float angle

the angle

constrainDefaultHeight

@NonNull
public void constrainDefaultHeight(@NonNull int viewId, @NonNull int height)

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

Parameters
@NonNull int viewId

ID of view to adjust its matchConstraintDefaultHeight

@NonNull int height

MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD

constrainDefaultWidth

@NonNull
public void constrainDefaultWidth(@NonNull int viewId, @NonNull int width)

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

Parameters
@NonNull int viewId

ID of view to adjust its matchConstraintDefaultWidth

@NonNull int width

SPREAD or WRAP

constrainHeight

@NonNull
public void constrainHeight(@NonNull int viewId, @NonNull int height)

Sets the height of the view. It can be a dimension, WRAP_CONTENT or .

Parameters
@NonNull int viewId

ID of view to adjust its height

@NonNull int height

the height of the view

constrainMaxHeight

@NonNull
public void constrainMaxHeight(@NonNull int viewId, @NonNull int height)

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

Parameters
@NonNull int viewId

ID of view to adjust it height

@NonNull int height

the maximum height of the constraint

constrainMaxWidth

@NonNull
public void constrainMaxWidth(@NonNull int viewId, @NonNull int width)

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

Parameters
@NonNull int viewId

ID of view to adjust its max height

@NonNull int width

the maximum width of the view

constrainMinHeight

@NonNull
public void constrainMinHeight(@NonNull int viewId, @NonNull int height)

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

Parameters
@NonNull int viewId

ID of view to adjust its min height

@NonNull int height

the minimum height of the view

constrainMinWidth

@NonNull
public void constrainMinWidth(@NonNull int viewId, @NonNull int width)

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

Parameters
@NonNull int viewId

ID of view to adjust its min height

@NonNull int width

the minimum width of the view

constrainPercentHeight

@NonNull
public void constrainPercentHeight(@NonNull int viewId, @NonNull float percent)

Sets the height of the view as a percentage of the parent.

Parameters
@NonNull int viewId
@NonNull float percent

constrainPercentWidth

@NonNull
public void constrainPercentWidth(@NonNull int viewId, @NonNull float percent)

Sets the width of the view as a percentage of the parent.

Parameters
@NonNull int viewId
@NonNull float percent

constrainWidth

@NonNull
public void constrainWidth(@NonNull int viewId, @NonNull int width)

Sets the width of the view. It can be a dimension, WRAP_CONTENT or .

Parameters
@NonNull int viewId

ID of view to adjust its width

@NonNull int width

the width of the view

constrainedHeight

@NonNull
public void constrainedHeight(@NonNull int viewId, @NonNull boolean constrained)

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

Parameters
@NonNull int viewId

ID of view to adjust its matchConstraintDefaultHeight

@NonNull boolean constrained

if true height will be constrained

constrainedWidth

@NonNull
public void constrainedWidth(@NonNull int viewId, @NonNull boolean constrained)

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

Parameters
@NonNull int viewId

ID of view to adjust its matchConstraintDefaultWidth

@NonNull boolean constrained

if true with will be constrained

create

@NonNull
public void create(@NonNull int guidelineID, @NonNull int orientation)

Creates a ConstraintLayout virtual object. Currently only horizontal or vertical GuideLines.

Parameters
@NonNull int guidelineID

ID of guideline to create

@NonNull int orientation

the Orientation of the guideline

createBarrier

@NonNull
public void createBarrier(
    @NonNull int id,
    @NonNull int direction,
    @NonNull int margin,
    @NonNull Array<@NonNull int> referenced
)

Creates a ConstraintLayout Barrier object.

Parameters
@NonNull int id
@NonNull int direction

Barrier.{LEFT,RIGHT,TOP,BOTTOM,START,END}

@NonNull Array<@NonNull int> referenced

createHorizontalChain

@NonNull
public void createHorizontalChain(
    @NonNull int leftId,
    @NonNull int leftSide,
    @NonNull int rightId,
    @NonNull int rightSide,
    @NonNull Array<@NonNull int> chainIds,
    @NonNull Array<@NonNull float> weights,
    @NonNull int style
)

Spaces a set of widgets horizontally between the view startID and endId. Widgets can be spaced with weights. This operation sets all the related margins to 0.

(for sides see: { } , { { } The id of the widget to connect to or PARENT_ID the side of the start to connect to The id of the widget to connect to or PARENT_ID the side of the right to connect to The widgets in the chain The weight to assign to each element in the chain or null The type of chain

createHorizontalChainRtl

@NonNull
public void createHorizontalChainRtl(
    @NonNull int startId,
    @NonNull int startSide,
    @NonNull int endId,
    @NonNull int endSide,
    @NonNull Array<@NonNull int> chainIds,
    @NonNull Array<@NonNull float> weights,
    @NonNull int style
)

Spaces a set of widgets horizontal between the view startID and endId. Widgets can be spaced with weights. (for sides see: { } , { { } ) The id of the widget to connect to or PARENT_ID the side of the start to connect to The id of the widget to connect to or PARENT_ID the side of the end to connect to The widgets in the chain The weight to assign to each element in the chain or null The type of chain

createVerticalChain

@NonNull
public void createVerticalChain(
    @NonNull int topId,
    @NonNull int topSide,
    @NonNull int bottomId,
    @NonNull int bottomSide,
    @NonNull Array<@NonNull int> chainIds,
    @NonNull Array<@NonNull float> weights,
    @NonNull int style
)

Spaces a set of widgets vertically between the view topId and bottomId. Widgets can be spaced with weights. This operation sets all the related margins to 0.

(for sides see: { } ) The id of the widget to connect to or PARENT_ID the side of the start to connect to The id of the widget to connect to or PARENT_ID the side of the right to connect to widgets to use as a chain can be null set the style of the chain

dump

@NonNull
public void dump(@NonNull MotionScene scene, @NonNull Array<@NonNull int> ids)

Dump the contents

Parameters
@NonNull MotionScene scene
@NonNull Array<@NonNull int> ids

getApplyElevation

@NonNull
public boolean getApplyElevation(@NonNull int viewId)

return with the constraint set will apply elevation for the specified view.

Returns
boolean

true if the elevation will be set on this view (default is false)

getConstraint

@NonNull
public ConstraintSet.Constraint getConstraint(@NonNull int id)

getHeight

@NonNull
public int getHeight(@NonNull int viewId)

Get the height set in the view

Parameters
@NonNull int viewId

the id of the view

Returns
int

return the height constraint of the view

getKnownIds

@NonNull
public Array<@NonNull int> getKnownIds()

getParameters

@NonNull
public ConstraintSet.Constraint getParameters(@NonNull int mId)

getReferencedIds

@NonNull
public Array<@NonNull int> getReferencedIds(@NonNull int id)

get the reference id's of a helper.

Parameters
@NonNull int id
Returns
Array<@NonNull int>

array of id's

getVisibility

@NonNull
public int getVisibility(@NonNull int viewId)

Get the visibility flag set in this view

Parameters
@NonNull int viewId

the id of the view

Returns
int

the visibility constraint for the view

getVisibilityMode

@NonNull
public int getVisibilityMode(@NonNull int viewId)

ConstraintSet will not setVisibility. VISIBILITY_MODE_IGNORE or .

Parameters
@NonNull int viewId

ID of view

getWidth

@NonNull
public int getWidth(@NonNull int viewId)

Get the width set in the view

Parameters
@NonNull int viewId

the id of the view

Returns
int

return the width constraint of the view

isForceId

@NonNull
public boolean isForceId()

Enforce id are required for all ConstraintLayout children to use ConstraintSet. default = true;

load

@NonNull
public void load(@NonNull Context context, @NonNull int resourceId)

Load a constraint set from a constraintSet.xml file. Note. Do NOT use this to load a layout file. It will fail silently as there is no efficient way to differentiate.

Parameters
@NonNull Context context

the context for the inflation

@NonNull int resourceId

id of xml file in res/xml/

load

@NonNull
public void load(@NonNull Context context, @NonNull XmlPullParser parser)

Load a constraint set from a constraintSet.xml file

Parameters
@NonNull Context context

the context for the inflation

@NonNull XmlPullParser parser

id of xml file in res/xml/

parseColorAttributes

@NonNull
public void parseColorAttributes(
    @NonNull ConstraintSet.Constraint set,
    @NonNull String attributes
)

parseFloatAttributes

@NonNull
public void parseFloatAttributes(
    @NonNull ConstraintSet.Constraint set,
    @NonNull String attributes
)

parseIntAttributes

@NonNull
public void parseIntAttributes(
    @NonNull ConstraintSet.Constraint set,
    @NonNull String attributes
)

parseStringAttributes

@NonNull
public void parseStringAttributes(
    @NonNull ConstraintSet.Constraint set,
    @NonNull String attributes
)

readFallback

@NonNull
public void readFallback(@NonNull ConstraintSet set)

This will copy Constraints from the ConstraintSet

Parameters
@NonNull ConstraintSet set

readFallback

@NonNull
public void readFallback(@NonNull ConstraintLayout constraintLayout)

This will copy Constraints from the ConstraintLayout if it does not have parameters

Parameters
@NonNull ConstraintLayout constraintLayout

removeAttribute

@NonNull
public void removeAttribute(@NonNull String attributeName)

removeFromHorizontalChain

@NonNull
public void removeFromHorizontalChain(@NonNull int viewId)

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

Parameters
@NonNull int viewId

the view to be removed

removeFromVerticalChain

@NonNull
public void removeFromVerticalChain(@NonNull int viewId)

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.

Parameters
@NonNull int viewId

the view to be removed

setAlpha

@NonNull
public void setAlpha(@NonNull int viewId, @NonNull float alpha)

Adjust the alpha of a view.

Parameters
@NonNull int viewId

ID of view to adjust the vertical

@NonNull float alpha

the alpha

setApplyElevation

@NonNull
public void setApplyElevation(@NonNull int viewId, @NonNull boolean apply)

set if elevation will be applied to the view. Elevation logic is based on style and animation. By default it is not used because it would lead to unexpected results.

Parameters
@NonNull boolean apply

true if this constraint set applies elevation to this view

setBarrierType

@NonNull
public void setBarrierType(@NonNull int id, @NonNull int type)

setColorValue

@NonNull
public void setColorValue(
    @NonNull int viewId,
    @NonNull String attributeName,
    @NonNull int value
)

setDimensionRatio

@NonNull
public void setDimensionRatio(@NonNull int viewId, @NonNull String ratio)

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

Parameters
@NonNull int viewId

ID of view to constrain

@NonNull String ratio

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

setEditorAbsoluteX

@NonNull
public void setEditorAbsoluteX(@NonNull int viewId, @NonNull int position)

setEditorAbsoluteY

@NonNull
public void setEditorAbsoluteY(@NonNull int viewId, @NonNull int position)

setElevation

@NonNull
public void setElevation(@NonNull int viewId, @NonNull float elevation)

Adjust the elevation of a view.

Parameters
@NonNull int viewId

ID of view to adjust the elevation

@NonNull float elevation

the elevation

setFloatValue

@NonNull
public void setFloatValue(
    @NonNull int viewId,
    @NonNull String attributeName,
    @NonNull float value
)

setForceId

@NonNull
public void setForceId(@NonNull boolean forceId)

Enforce id are required for all ConstraintLayout children to use ConstraintSet. default = true;

Parameters
@NonNull boolean forceId

setGoneMargin

@NonNull
public void setGoneMargin(@NonNull int viewId, @NonNull int anchor, @NonNull int value)

Sets the gone margin.

Parameters
@NonNull int viewId

ID of view to adjust the margin on

@NonNull int anchor

The side to adjust the margin on

@NonNull int value

The new value for the margin

setGuidelineBegin

@NonNull
public void setGuidelineBegin(@NonNull int guidelineID, @NonNull int margin)

Set the guideline's distance form the top or left edge.

Parameters
@NonNull int guidelineID

ID of the guideline

@NonNull int margin

the distance to the top or left edge

setGuidelineEnd

@NonNull
public void setGuidelineEnd(@NonNull int guidelineID, @NonNull int margin)

Set a guideline's distance to end.

Parameters
@NonNull int guidelineID

ID of the guideline

@NonNull int margin

the margin to the right or bottom side of container

setGuidelinePercent

@NonNull
public void setGuidelinePercent(@NonNull int guidelineID, @NonNull float ratio)

Set a Guideline's percent.

Parameters
@NonNull int guidelineID

ID of the guideline

@NonNull float ratio

the ratio between the gap on the left and right 0.0 is top/left 0.5 is middle

setHorizontalBias

@NonNull
public void setHorizontalBias(@NonNull int viewId, @NonNull float bias)

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

Parameters
@NonNull int viewId

ID of view to adjust the horizontal

@NonNull float bias

the new bias 0.5 is in the middle

setHorizontalChainStyle

@NonNull
public void setHorizontalChainStyle(@NonNull int viewId, @NonNull int chainStyle)

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
@NonNull int viewId

ID of view to adjust its HorizontalChainStyle

@NonNull int chainStyle

the weight that we can use to distribute the horizontal space

setHorizontalWeight

@NonNull
public void setHorizontalWeight(@NonNull int viewId, @NonNull float weight)

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
@NonNull int viewId

ID of view to adjust its HorizontalWeight

@NonNull float weight

the weight that we can use to distribute the horizontal space

setIntValue

@NonNull
public void setIntValue(
    @NonNull int viewId,
    @NonNull String attributeName,
    @NonNull int value
)

setLayoutWrapBehavior

@NonNull
public void setLayoutWrapBehavior(@NonNull int viewId, @NonNull int behavior)

Sets the wrap behavior of the widget in the parent's wrap computation

setMargin

@NonNull
public void setMargin(@NonNull int viewId, @NonNull int anchor, @NonNull int value)

Sets the margin.

Parameters
@NonNull int viewId

ID of view to adjust the margin on

@NonNull int anchor

The side to adjust the margin on

@NonNull int value

The new value for the margin

setReferencedIds

@NonNull
public void setReferencedIds(@NonNull int id, @NonNull Array<@NonNull int> referenced)

sets the reference id's of a barrier.

Parameters
@NonNull int id
@NonNull Array<@NonNull int> referenced

setRotation

@NonNull
public void setRotation(@NonNull int viewId, @NonNull float rotation)

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

Parameters
@NonNull int viewId

ID of view to adjust th Z rotation

@NonNull float rotation

the rotation about the X axis

setRotationX

@NonNull
public void setRotationX(@NonNull int viewId, @NonNull float rotationX)

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

Parameters
@NonNull int viewId

ID of view to adjust th X rotation

@NonNull float rotationX

the rotation about the X axis

setRotationY

@NonNull
public void setRotationY(@NonNull int viewId, @NonNull float rotationY)

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

Parameters
@NonNull int viewId

ID of view to adjust the Y rotation

@NonNull float rotationY

the rotationY

setScaleX

@NonNull
public void setScaleX(@NonNull int viewId, @NonNull float scaleX)

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

Parameters
@NonNull int viewId

ID of view to adjust the scale in X

@NonNull float scaleX

the scale in X

setScaleY

@NonNull
public void setScaleY(@NonNull int viewId, @NonNull float scaleY)

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

Parameters
@NonNull int viewId

ID of view to adjust the scale in Y

@NonNull float scaleY

the scale in Y

setStringValue

@NonNull
public void setStringValue(
    @NonNull int viewId,
    @NonNull String attributeName,
    @NonNull String value
)

setTransformPivot

@NonNull
public void setTransformPivot(
    @NonNull int viewId,
    @NonNull float transformPivotX,
    @NonNull float transformPivotY
)

Set X,Y location of the pivot point around which the view will rotate and scale. use Float.NaN to clear the pivot value. Note: once an actual View has had its pivot set it cannot be cleared.

Parameters
@NonNull int viewId

ID of view to adjust the transforms pivot point

@NonNull float transformPivotX

X location of the pivot point.

@NonNull float transformPivotY

Y location of the pivot point.

setTransformPivotX

@NonNull
public void setTransformPivotX(@NonNull int viewId, @NonNull float transformPivotX)

Set X location of the pivot point around which the view will rotate and scale. use Float.NaN to clear the pivot value. Note: once an actual View has had its pivot set it cannot be cleared.

Parameters
@NonNull int viewId

ID of view to adjust the transforms pivot point about X

@NonNull float transformPivotX

X location of the pivot point.

setTransformPivotY

@NonNull
public void setTransformPivotY(@NonNull int viewId, @NonNull float transformPivotY)

Set Y location of the pivot point around which the view will rotate and scale. use Float.NaN to clear the pivot value. Note: once an actual View has had its pivot set it cannot be cleared.

Parameters
@NonNull int viewId

ID of view to adjust the transforms pivot point about Y

@NonNull float transformPivotY

Y location of the pivot point.

setTranslation

@NonNull
public void setTranslation(
    @NonNull int viewId,
    @NonNull float translationX,
    @NonNull float translationY
)

Adjust the post-layout translation of a view.

Parameters
@NonNull int viewId

ID of view to adjust its translation in X & Y

@NonNull float translationX

the translation in X

@NonNull float translationY

the translation in Y

setTranslationX

@NonNull
public void setTranslationX(@NonNull int viewId, @NonNull float translationX)

Adjust the post-layout X translation of a view.

Parameters
@NonNull int viewId

ID of view to translate in X

@NonNull float translationX

the translation in X

setTranslationY

@NonNull
public void setTranslationY(@NonNull int viewId, @NonNull float translationY)

Adjust the post-layout Y translation of a view.

Parameters
@NonNull int viewId

ID of view to to translate in Y

@NonNull float translationY

the translation in Y

setTranslationZ

@NonNull
public void setTranslationZ(@NonNull int viewId, @NonNull float translationZ)

Adjust the translation in Z of a view.

Parameters
@NonNull int viewId

ID of view to adjust

@NonNull float translationZ

the translationZ

setValidateOnParse

@NonNull
public void setValidateOnParse(@NonNull boolean validate)

If true perform validation checks when parsing ConstraintSets This will slow down parsing and should only be used for debugging

Parameters
@NonNull boolean validate

setVerticalBias

@NonNull
public void setVerticalBias(@NonNull int viewId, @NonNull float bias)

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

Parameters
@NonNull int viewId

ID of view to adjust the vertical

@NonNull float bias

the new bias 0.5 is in the middle

setVerticalChainStyle

@NonNull
public void setVerticalChainStyle(@NonNull int viewId, @NonNull int chainStyle)

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 vertical bias attribute of the child will then affect the positioning of the packed elements
Parameters
@NonNull int viewId

ID of view to adjust its VerticalChainStyle

@NonNull int chainStyle

the weight that we can use to distribute the horizontal space

setVerticalWeight

@NonNull
public void setVerticalWeight(@NonNull int viewId, @NonNull float weight)

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
@NonNull int viewId

ID of view to adjust its VerticalWeight

@NonNull float weight

the weight that we can use to distribute the vertical space

setVisibility

@NonNull
public void setVisibility(@NonNull int viewId, @NonNull int visibility)

Adjust the visibility of a view.

Parameters
@NonNull int viewId

ID of view to adjust the vertical

@NonNull int visibility

the visibility

setVisibilityMode

@NonNull
public void setVisibilityMode(@NonNull int viewId, @NonNull int visibilityMode)

ConstraintSet will not setVisibility. VISIBILITY_MODE_IGNORE or .

Parameters
@NonNull int viewId

ID of view

@NonNull int visibilityMode

writeState

@NonNull
public void writeState(
    @NonNull Writer writer,
    @NonNull ConstraintLayout layout,
    @NonNull int flags
)