Skip to content

Most visited

Recently visited

navigation

ConstraintSet

public class ConstraintSet
extends Object

java.lang.Object
   ↳ android.support.constraint.ConstraintSet


This class allows you to define programmatically a set of constraints to be used with ConstraintLayout. It lets you create and save constraints, and apply them to an existing ConstraintLayout. ConstraintsSet can be created in various ways:

  • Manually
    c = new ConstraintSet(); c.connect(....);
  • from a R.layout.* object
    c.clone(context, R.layout.layout1);
  • from a ConstraintLayout
    c.clone(clayout);

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

int BASELINE

The baseline of the text in a view.

int BOTTOM

The bottom side of a view.

int END

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

int GONE

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

int HORIZONTAL_GUIDELINE

Used to create a horizontal create guidelines.

int INVISIBLE

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

int LEFT

The left side of a view.

int MATCH_CONSTRAINT

Dimension will be controlled by constraints

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

Used to indicate a parameter is cleared or not set

int VERTICAL_GUIDELINE

Used to create a vertical create guidelines.

int VISIBLE

This view is visible.

int WRAP_CONTENT

Dimension will set by the view's content

Fields

public static final int CHAIN_PACKED

Chain packed style

public static final int CHAIN_SPREAD

Chain spread style

public static final int CHAIN_SPREAD_INSIDE

Chain spread inside style

public static final int HORIZONTAL

The horizontal orientation.

public static final int MATCH_CONSTRAINT_SPREAD

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

public static final int MATCH_CONSTRAINT_WRAP

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

public static final int VERTICAL

The vertical orientation.

Public constructors

ConstraintSet()

Public methods

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

Adds a view to a horizontal chain.

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

Adds a view to a horizontal chain.

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

Adds a view to a vertical chain.

void applyTo(ConstraintLayout constraintLayout)

Apply the constraints to a ConstraintLayout.

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

Center widget between the other two widgets.

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

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

void centerHorizontally(int viewId, int toView)

Centers the view horizontally relative to toView's position.

void centerHorizontallyRtl(int viewId, int toView)

Centers the view horizontally relative to toView's position.

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

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

void centerVertically(int viewId, int toView)

Centers the view vertically relative to toView's position.

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

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

void clear(int viewId, int anchor)

Remove a constraint from this view.

void clear(int viewId)

Remove all constraints from this view.

void clone(ConstraintLayout constraintLayout)

Copy the layout parameters of a ConstraintLayout.

void clone(ConstraintSet set)

Copy the constraints from a layout.

void clone(Context context, int constraintLayoutId)

Copy the constraints from a layout.

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

Create a constraint between two widgets.

void constrainDefaultHeight(int viewId, int height)

Sets how the height is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD.

void constrainDefaultWidth(int viewId, int width)

Sets how the width is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD.

void constrainHeight(int viewId, int height)

Sets the height of the view.

void constrainMaxHeight(int viewId, int height)

Sets the maximum height of the view.

void constrainMaxWidth(int viewId, int width)

Sets the maximum width of the view.

void constrainMinHeight(int viewId, int height)

Sets the height of the view.

void constrainMinWidth(int viewId, int width)

Sets the width of the view.

void constrainWidth(int viewId, int width)

Sets the width of the view.

void create(int guidelineID, int orientation)

Creates a ConstraintLayout virtual object.

void createHorizontalChain(int leftId, int leftSide, int rightId, int rightSide, int[] chainIds, float[] weights, int style)

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

void createHorizontalChainRtl(int startId, int startSide, int endId, int endSide, int[] chainIds, float[] weights, int style)

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

void createVerticalChain(int topId, int topSide, int bottomId, int bottomSide, int[] chainIds, float[] weights, int style)

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

boolean getApplyElevation(int viewId)

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

void load(Context context, int resourceId)

Load a constraint set from a constraintSet.xml file

void removeFromHorizontalChain(int viewId)

Removes a view from a horizontal chain.

void removeFromVerticalChain(int viewId)

Removes a view from a vertical chain.

void setAlpha(int viewId, float alpha)

Adjust the alpha of a view.

void setApplyElevation(int viewId, boolean apply)

set if elevation will be applied to the view.

void setDimensionRatio(int viewId, String ratio)

Constrains the views aspect ratio.

void setElevation(int viewId, float elevation)

Adjust the elevation of a view.

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

Sets the gone margin.

void setGuidelineBegin(int guidelineID, int margin)

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

void setGuidelineEnd(int guidelineID, int margin)

Set a guideline's distance to end.

void setGuidelinePercent(int guidelineID, float ratio)

Set a Guideline's percent.

void setHorizontalBias(int viewId, float bias)

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

void setHorizontalChainStyle(int viewId, int chainStyle)

How the elements of the horizontal chain will be positioned.

void setHorizontalWeight(int viewId, 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

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

Sets the margin.

void setRotationX(int viewId, float rotationX)

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

void setRotationY(int viewId, float rotationY)

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

void setScaleX(int viewId, float scaleX)

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

void setScaleY(int viewId, float scaleY)

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

void setTransformPivot(int viewId, float transformPivotX, float transformPivotY)

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

void setTransformPivotX(int viewId, float transformPivotX)

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

void setTransformPivotY(int viewId, float transformPivotY)

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

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

Adjust the post-layout translation of a view.

void setTranslationX(int viewId, float translationX)

Adjust the post-layout X translation of a view.

void setTranslationY(int viewId, float translationY)

Adjust the post-layout Y translation of a view.

void setTranslationZ(int viewId, float translationZ)

Adjust the translation in Z of a view.

void setVerticalBias(int viewId, float bias)

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

void setVerticalChainStyle(int viewId, int chainStyle)

How the elements of the vertical chain will be positioned.

void setVerticalWeight(int viewId, 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

void setVisibility(int viewId, int visibility)

Adjust the visibility of a view.

Inherited methods

From class java.lang.Object

Constants

BASELINE

int BASELINE

The baseline of the text in a view.

Constant Value: 5 (0x00000005)

BOTTOM

int BOTTOM

The bottom side of a view.

Constant Value: 4 (0x00000004)

END

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)

GONE

int GONE

This view is gone, and will not take any space for layout purposes. Use with setVisibility(int, int) and android:visibility.

Constant Value: 8 (0x00000008)

HORIZONTAL_GUIDELINE

int HORIZONTAL_GUIDELINE

Used to create a horizontal create guidelines.

Constant Value: 0 (0x00000000)

INVISIBLE

int INVISIBLE

This view is invisible, but it still takes up space for layout purposes. Use with setVisibility(int, int) and android:visibility.

Constant Value: 4 (0x00000004)

LEFT

int LEFT

The left side of a view.

Constant Value: 1 (0x00000001)

MATCH_CONSTRAINT

int MATCH_CONSTRAINT

Dimension will be controlled by constraints

Constant Value: 0 (0x00000000)

PARENT_ID

int PARENT_ID

References the id of the parent. Used in:

Constant Value: 0 (0x00000000)

RIGHT

int RIGHT

The right side of a view.

Constant Value: 2 (0x00000002)

START

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

int TOP

The top of a view.

Constant Value: 3 (0x00000003)

UNSET

int UNSET

Used to indicate a parameter is cleared or not set

Constant Value: -1 (0xffffffff)

VERTICAL_GUIDELINE

int VERTICAL_GUIDELINE

Used to create a vertical create guidelines. see create(int, int)

Constant Value: 1 (0x00000001)

VISIBLE

int VISIBLE

This view is visible. Use with setVisibility(int, int) and android:visibility.

Constant Value: 0 (0x00000000)

WRAP_CONTENT

int WRAP_CONTENT

Dimension will set by the view's content

Constant Value: -2 (0xfffffffe)

Fields

CHAIN_PACKED

int CHAIN_PACKED

Chain packed style

CHAIN_SPREAD

int CHAIN_SPREAD

Chain spread style

CHAIN_SPREAD_INSIDE

int CHAIN_SPREAD_INSIDE

Chain spread inside style

HORIZONTAL

int HORIZONTAL

The horizontal orientation.

MATCH_CONSTRAINT_SPREAD

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

int MATCH_CONSTRAINT_WRAP

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

VERTICAL

int VERTICAL

The vertical orientation.

Public constructors

ConstraintSet

ConstraintSet ()

Public methods

addToHorizontalChain

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

Adds a view to a horizontal chain.

Parameters
viewId int: view to add
leftId int: view in chain to the left
rightId int: view in chain to the right

addToHorizontalChainRTL

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

Adds a view to a horizontal chain.

Parameters
viewId int: view to add
leftId int: view to the start side
rightId int: view to the end side

addToVerticalChain

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

Adds a view to a vertical chain.

Parameters
viewId int: view to add to a vertical chain
topId int: view above.
bottomId int: view below

applyTo

void applyTo (ConstraintLayout constraintLayout)

Apply the constraints to a ConstraintLayout.

Parameters
constraintLayout ConstraintLayout: to be modified

center

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

Center widget between the other two widgets.

Parameters
centerID int: ID of the widget to be centered
firstID int: ID of the first widget to connect the left or top of the widget to
firstSide int: the side of the widget to connect to
firstMargin int: the connection margin
secondId int: the ID of the second widget to connect to right or top of the widget to
secondSide int: the side of the widget to connect to
secondMargin int: the connection margin
bias float: the ratio between two connections

centerHorizontally

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

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

Parameters
centerID int: ID of widget to be centered
leftId int: The Id of the widget on the left side
leftSide int: The side of the leftId widget to connect to
leftMargin int: The margin on the left side
rightId int: The Id of the widget on the right side
rightSide int: The side of the rightId widget to connect to
rightMargin int: The margin on the right side
bias float: The ratio of the space on the left vs. right sides 0.5 is centered (default)

centerHorizontally

void centerHorizontally (int viewId, 
                int toView)

Centers the view horizontally relative to toView's position.

Parameters
viewId int: ID of view to center Horizontally
toView int: ID of view to center on (or in)

centerHorizontallyRtl

void centerHorizontallyRtl (int viewId, 
                int toView)

Centers the view horizontally relative to toView's position.

Parameters
viewId int: ID of view to center Horizontally
toView int: ID of view to center on (or in)

centerHorizontallyRtl

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

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

Parameters
centerID int: ID of widget to be centered
startId int: The Id of the widget on the start side (left in non rtl languages)
startSide int: The side of the startId widget to connect to
startMargin int: The margin on the start side
endId int: The Id of the widget on the start side (left in non rtl languages)
endSide int: The side of the endId widget to connect to
endMargin int: The margin on the end side
bias float: The ratio of the space on the start vs end side 0.5 is centered (default)

centerVertically

void centerVertically (int viewId, 
                int toView)

Centers the view vertically relative to toView's position.

Parameters
viewId int: ID of view to center Horizontally
toView int: ID of view to center on (or in)

centerVertically

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

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

Parameters
centerID int: ID of widget to be centered
topId int: The Id of the widget on the top side
topSide int: The side of the leftId widget to connect to
topMargin int: The margin on the top side
bottomId int: The Id of the widget on the bottom side
bottomSide int: The side of the bottomId widget to connect to
bottomMargin int: The margin on the bottom side
bias float: The ratio of the space on the top vs. bottom sides 0.5 is centered (default)

clear

void clear (int viewId, 
                int anchor)

Remove a constraint from this view.

Parameters
viewId int: ID of view to center on (or in)
anchor int: the Anchor to remove constraint from

clear

void clear (int viewId)

Remove all constraints from this view.

Parameters
viewId int: ID of view to remove all connections to

clone

void clone (ConstraintLayout constraintLayout)

Copy the layout parameters of a ConstraintLayout.

Parameters
constraintLayout ConstraintLayout: The ConstraintLayout to be copied

clone

void clone (ConstraintSet set)

Copy the constraints from a layout.

Parameters
set ConstraintSet: constraint set to copy

clone

void clone (Context context, 
                int constraintLayoutId)

Copy the constraints from a layout.

Parameters
context Context: the context for the layout inflation
constraintLayoutId int: the id of the layout file

connect

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

Create a constraint between two widgets.

Parameters
startID int: the ID of the widget to be constrained
startSide int: the side of the widget to constrain
endID int: the id of the widget to constrain to
endSide int: the side of widget to constrain to
margin int: the margin to constrain (margin must be postive)

constrainDefaultHeight

void constrainDefaultHeight (int viewId, 
                int height)

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

Parameters
viewId int: ID of view to adjust its matchConstraintDefaultHeight
height int: MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD

constrainDefaultWidth

void constrainDefaultWidth (int viewId, 
                int width)

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

Parameters
viewId int: ID of view to adjust its matchConstraintDefaultWidth
width int: SPREAD or WRAP

constrainHeight

void constrainHeight (int viewId, 
                int height)

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

Parameters
viewId int: ID of view to adjust its height
height int: the height of the constraint

constrainMaxHeight

void constrainMaxHeight (int viewId, 
                int height)

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

Parameters
viewId int: ID of view to adjust it height
height int: the height of the constraint

constrainMaxWidth

void constrainMaxWidth (int viewId, 
                int width)

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

Parameters
viewId int: ID of view to adjust its max height
width int: the width of the view

constrainMinHeight

void constrainMinHeight (int viewId, 
                int height)

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

Parameters
viewId int: ID of view to adjust its min height
height int: the minimum height of the view

constrainMinWidth

void constrainMinWidth (int viewId, 
                int width)

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

Parameters
viewId int: ID of view to adjust its min height
width int: the minimum width of the view

constrainWidth

void constrainWidth (int viewId, 
                int width)

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

Parameters
viewId int: ID of view to adjust its width
width int: the width of the view

create

void create (int guidelineID, 
                int orientation)

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

Parameters
guidelineID int: ID of guideline to create
orientation int: the Orientation of the guideline

createHorizontalChain

void createHorizontalChain (int leftId, 
                int leftSide, 
                int rightId, 
                int rightSide, 
                int[] chainIds, 
                float[] weights, 
                int style)

Spaces a set of widgets horizontal between the view startID and endId. Widgets can be spaced with weights.

Parameters
leftId int: The id of the widget to connect to or PARENT_ID
leftSide int: the side of the start to connect to
rightId int: The id of the widget to connect to or PARENT_ID
rightSide int: the side of the right to connect to
chainIds int: The widgets in the chain
weights float: The weight to assign to each element in the chain or null
style int: The type of chain

createHorizontalChainRtl

void createHorizontalChainRtl (int startId, 
                int startSide, 
                int endId, 
                int endSide, 
                int[] chainIds, 
                float[] weights, 
                int style)

Spaces a set of widgets horizontal between the view startID and endId. Widgets can be spaced with weights.

Parameters
startId int: The id of the widget to connect to or PARENT_ID
startSide int: the side of the start to connect to
endId int: The id of the widget to connect to or PARENT_ID
endSide int: the side of the end to connect to
chainIds int: The widgets in the chain
weights float: The weight to assign to each element in the chain or null
style int: The type of chain

createVerticalChain

void createVerticalChain (int topId, 
                int topSide, 
                int bottomId, 
                int bottomSide, 
                int[] chainIds, 
                float[] weights, 
                int style)

Spaces a set of widgets vertically between the view topId and bottomId. Widgets can be spaced with weights.

Parameters
topId int: The id of the widget to connect to or PARENT_ID
topSide int: the side of the start to connect to
bottomId int: The id of the widget to connect to or PARENT_ID
bottomSide int: the side of the right to connect to
chainIds int: widgets to use as a chain
weights float: can be null
style int: set the style of the chain

getApplyElevation

boolean getApplyElevation (int viewId)

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

Parameters
viewId int
Returns
boolean true if the elevation will be set on this view (default is false)

load

void load (Context context, 
                int resourceId)

Load a constraint set from a constraintSet.xml file

Parameters
context Context: the context for the inflation
resourceId int: id of xml file in res/xml/

removeFromHorizontalChain

void removeFromHorizontalChain (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
viewId int: the view to be removed

removeFromVerticalChain

void removeFromVerticalChain (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
viewId int: the view to be removed

setAlpha

void setAlpha (int viewId, 
                float alpha)

Adjust the alpha of a view.

Parameters
viewId int: ID of view to adjust the vertical
alpha float: the alpha

setApplyElevation

void setApplyElevation (int viewId, 
                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
viewId int
apply boolean: true if this constraint set applies elevation to this view

setDimensionRatio

void setDimensionRatio (int viewId, 
                String ratio)

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

Parameters
viewId int: ID of view to constrain
ratio String: The ratio of the width to height (width / height)

setElevation

void setElevation (int viewId, 
                float elevation)

Adjust the elevation of a view.

Parameters
viewId int: ID of view to adjust the elevation
elevation float: the elevation

setGoneMargin

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

Sets the gone margin.

Parameters
viewId int: ID of view to adjust the margin on
anchor int: The side to adjust the margin on
value int: The new value for the margin

setGuidelineBegin

void setGuidelineBegin (int guidelineID, 
                int margin)

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

Parameters
guidelineID int: ID of the guideline
margin int: the distance to the top or left edge

setGuidelineEnd

void setGuidelineEnd (int guidelineID, 
                int margin)

Set a guideline's distance to end.

Parameters
guidelineID int: ID of the guideline
margin int: the margin to the right or bottom side of container

setGuidelinePercent

void setGuidelinePercent (int guidelineID, 
                float ratio)

Set a Guideline's percent.

Parameters
guidelineID int: ID of the guideline
ratio float: the ratio between the gap on the left and right 0.0 is top/left 0.5 is middle

setHorizontalBias

void setHorizontalBias (int viewId, 
                float bias)

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

Parameters
viewId int: ID of view to adjust the horizontal
bias float: the new bias 0.5 is in the middle

setHorizontalChainStyle

void setHorizontalChainStyle (int viewId, 
                int chainStyle)

How the elements of the horizontal chain will be positioned. The possible values are:

  • -- the elements will be spread out
  • -- similar, but the endpoints of the chain will not be spread out
  • -- 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
viewId int: ID of view to adjust its HorizontalChainStyle
chainStyle int: the weight that we can use to distribute the horizontal space

See also:

setHorizontalWeight

void setHorizontalWeight (int viewId, 
                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
viewId int: ID of view to adjust its HorizontalWeight
weight float: the weight that we can use to distribute the horizontal space

setMargin

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

Sets the margin.

Parameters
viewId int: ID of view to adjust the margin on
anchor int: The side to adjust the margin on
value int: The new value for the margin

setRotationX

void setRotationX (int viewId, 
                float rotationX)

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

Parameters
viewId int: ID of view to adjust th X rotation
rotationX float: the rotation about the X axis

setRotationY

void setRotationY (int viewId, 
                float rotationY)

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

Parameters
viewId int: ID of view to adjust the Y rotation
rotationY float: the rotationY

setScaleX

void setScaleX (int viewId, 
                float scaleX)

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

Parameters
viewId int: ID of view to adjust the scale in X
scaleX float: the scale in X

setScaleY

void setScaleY (int viewId, 
                float scaleY)

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

Parameters
viewId int: ID of view to adjust the scale in Y
scaleY float: the scale in Y

setTransformPivot

void setTransformPivot (int viewId, 
                float transformPivotX, 
                float transformPivotY)

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

Parameters
viewId int: ID of view to adjust the transforms pivot point
transformPivotX float: X location of the pivot point.
transformPivotY float: Y location of the pivot point.

setTransformPivotX

void setTransformPivotX (int viewId, 
                float transformPivotX)

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

Parameters
viewId int: ID of view to adjust the transforms pivot point about X
transformPivotX float: X location of the pivot point.

setTransformPivotY

void setTransformPivotY (int viewId, 
                float transformPivotY)

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

Parameters
viewId int: ID of view to adjust the transforms pivot point about Y
transformPivotY float: Y location of the pivot point.

setTranslation

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

Adjust the post-layout translation of a view.

Parameters
viewId int: ID of view to adjust its translation in X & Y
translationX float: the translation in X
translationY float: the translation in Y

setTranslationX

void setTranslationX (int viewId, 
                float translationX)

Adjust the post-layout X translation of a view.

Parameters
viewId int: ID of view to translate in X
translationX float: the translation in X

setTranslationY

void setTranslationY (int viewId, 
                float translationY)

Adjust the post-layout Y translation of a view.

Parameters
viewId int: ID of view to to translate in Y
translationY float: the translation in Y

setTranslationZ

void setTranslationZ (int viewId, 
                float translationZ)

Adjust the translation in Z of a view.

Parameters
viewId int: ID of view to adjust
translationZ float: the translationZ

setVerticalBias

void setVerticalBias (int viewId, 
                float bias)

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

Parameters
viewId int: ID of view to adjust the vertical
bias float: the new bias 0.5 is in the middle

setVerticalChainStyle

void setVerticalChainStyle (int viewId, 
                int chainStyle)

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

  • -- the elements will be spread out
  • -- similar, but the endpoints of the chain will not be spread out
  • -- 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
viewId int: ID of view to adjust its VerticalChainStyle
chainStyle int: the weight that we can use to distribute the horizontal space

See also:

setVerticalWeight

void setVerticalWeight (int viewId, 
                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
viewId int: ID of view to adjust its VerticalWeight
weight float: the weight that we can use to distribute the horizontal space

setVisibility

void setVisibility (int viewId, 
                int visibility)

Adjust the visibility of a view.

Parameters
viewId int: ID of view to adjust the vertical
visibility int: the visibility
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.