ConstraintSet
public class ConstraintSet
Defines a set of constraints to be used with ConstraintLayout.
ConstraintSet enables you create and save constraints and apply them to an existing ConstraintLayout. For details about constraint behaviour, see ConstraintLayout.
ConstraintsSet can be created in various ways:
- Manually —
c = new ConstraintSet(); c.connect(...); - From an
R.layout.*object —c.clone(context, R.layout.layout1); - From a
ConstraintLayout—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 ConstraintSet. ConstraintSet mConstraintSet2 = new ConstraintSet(); // Create a ConstraintSet. ConstraintLayout mConstraintLayout; // Cache the ConstraintLayout. boolean mOld = true; 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
Nested types |
|---|
public class ConstraintSet.Constraint |
public class ConstraintSet.Layout |
public class ConstraintSet.Motion |
public class ConstraintSet.PropertySet |
public class ConstraintSet.Transform |
Constants |
|
|---|---|
static final int |
BASELINE = 5The baseline of the text in a view. |
static final int |
BOTTOM = 4The bottom side of a view. |
static final int |
CHAIN_PACKED = 2Chain packed style |
static final int |
CHAIN_SPREAD = 0Chain spread style |
static final int |
Chain spread inside style |
static final int |
CIRCLE_REFERENCE = 8Circle reference from a view. |
static final int |
END = 7The right side of a view in left to right languages. |
static final int |
GONE = 8This view is gone, and will not take any space for layout purposes. |
static final int |
HORIZONTAL = 0The horizontal orientation. |
static final int |
Used to create a horizontal create guidelines. |
static final int |
INVISIBLE = 4This view is invisible, but it still takes up space for layout purposes. |
static final int |
LEFT = 1The left side of a view. |
static final int |
MATCH_CONSTRAINT = 0Dimension will be controlled by constraints |
static final int |
|
static final int |
Calculate the size of a view in 0 dp by reducing the constrains gaps as much as possible |
static final int |
How to calculate the size of a view in 0 dp by using its wrap_content size |
static final int |
PARENT_ID = 0References the id of the parent. |
static final int |
RIGHT = 2The right side of a view. |
static final int |
|
static final int |
ROTATE_NONE = 0 |
static final int |
|
static final int |
|
static final int |
|
static final int |
START = 6The left side of a view in left to right languages. |
static final int |
TOP = 3The top of a view. |
static final int |
UNSET = -1Used to indicate a parameter is cleared or not set |
static final int |
VERTICAL = 1The vertical orientation. |
static final int |
Used to create a vertical create guidelines. see |
static final int |
|
static final int |
|
static final int |
VISIBLE = 0This view is visible. |
static final int |
WRAP_CONTENT = -2Dimension will set by the view's content |
Public constructors |
|---|
Public methods |
|
|---|---|
void |
addColorAttributes(String[] attributeName)Add attribute of type Color |
void |
addFloatAttributes(String[] attributeName)Add attribute of type float |
void |
addIntAttributes(String[] attributeName)Add attribute of type Int |
void |
addStringAttributes(String[] attributeName)Add attribute of type string |
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 |
applyCustomAttributes(ConstraintLayout constraintLayout)Apply custom attributes alone |
void |
Get the delta form the ConstraintSet and aplly to this |
void |
applyTo(ConstraintLayout constraintLayout)Apply the constraints to a ConstraintLayout. |
void |
applyToHelper(Apply Layout to Helper widget |
void |
applyToLayoutParams(int id, ConstraintLayout.LayoutParams layoutParams)Fill in a ConstraintLayout LayoutParam based on the id. |
void |
applyToWithoutCustom(ConstraintLayout constraintLayout)Apply the constraints to a ConstraintLayout. |
static ConstraintSet.Constraint |
buildDelta(Context context, XmlPullParser parser)Used to read a ConstraintDelta |
void |
center(Center widget between the other two widgets. |
void |
centerHorizontally(int viewId, int toView)Centers the view horizontally relative to toView's position. |
void |
centerHorizontally(Centers the widget horizontally to the left and right side on another widgets sides. |
void |
centerHorizontallyRtl(int viewId, int toView)Centers the view horizontally relative to toView's position. |
void |
centerHorizontallyRtl(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(Centers the widgets vertically to the top and bottom side on another widgets sides. |
void |
clear(int viewId)Remove all constraints from this view. |
void |
clear(int viewId, int anchor)Remove a constraint from this view. |
void |
clone(ConstraintLayout constraintLayout)Copy the layout parameters of a ConstraintLayout. |
void |
clone(Constraints constraints)Copy the layout parameters of a ConstraintLayout. |
void |
clone(ConstraintSet set)Copy the constraints from a layout. |
void |
Copy the constraints from a layout. |
void |
connect(int startID, int startSide, int endID, int endSide)Create a constraint between two widgets. |
void |
connect(int startID, int startSide, int endID, int endSide, int margin)Create a constraint between two widgets. |
void |
constrainCircle(int viewId, int id, int radius, float angle)Constrain the view on a circle constraint |
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 |
constrainPercentHeight(int viewId, float percent)Sets the height of the view as a percentage of the parent. |
void |
constrainPercentWidth(int viewId, float percent)Sets the width of the view as a percentage of the parent. |
void |
constrainWidth(int viewId, int width)Sets the width of the view. |
void |
constrainedHeight(int viewId, boolean constrained)Sets how the height is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD. |
void |
constrainedWidth(int viewId, boolean constrained)Sets how the width is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD. |
void |
create(int guidelineID, int orientation)Creates a ConstraintLayout virtual object. |
void |
createBarrier(int id, int direction, int margin, int[] referenced)Creates a ConstraintLayout Barrier object. |
void |
createHorizontalChain(Spaces a set of widgets horizontally between the view startID and endId. |
void |
createHorizontalChainRtl(Spaces a set of widgets horizontal between the view startID and endId. |
void |
createVerticalChain(Spaces a set of widgets vertically between the view topId and bottomId. |
void |
dump(MotionScene scene, int[] ids)Dump the contents |
boolean |
getApplyElevation(int viewId)return with the constraint set will apply elevation for the specified view. |
ConstraintSet.Constraint |
getConstraint(int id) |
HashMap<String, ConstraintAttribute> |
|
int |
getHeight(int viewId)Get the height set in the view |
int[] |
|
ConstraintSet.Constraint |
getParameters(int mId) |
int[] |
getReferencedIds(int id)get the reference id's of a helper. |
String[] |
Get the types associated with this ConstraintSet The types mechanism allows you to tag the constraint set with a series of string to define properties of a ConstraintSet |
int |
getVisibility(int viewId)Get the visibility flag set in this view |
int |
getVisibilityMode(int viewId)ConstraintSet will not setVisibility. |
int |
getWidth(int viewId)Get the width set in the view |
boolean |
Enforce id are required for all ConstraintLayout children to use ConstraintSet. default = true; |
boolean |
If true perform validation checks when parsing ConstraintSets This will slow down parsing and should only be used for debugging |
void |
load(Context context, XmlPullParser parser)Load a constraint set from a constraintSet.xml file |
void |
Load a constraint set from a constraintSet.xml file. |
boolean |
matchesLabels(String[] types)Test if the list of strings matches labels defined on this constraintSet |
void |
parseColorAttributes(ConstraintSet.Constraint set, String attributes)Parse color |
void |
parseFloatAttributes(ConstraintSet.Constraint set, String attributes)Parse floats |
void |
parseIntAttributes(ConstraintSet.Constraint set, String attributes)Parse int |
void |
parseStringAttributes(ConstraintSet.Constraint set, String attributes)Parse string |
void |
readFallback(ConstraintLayout constraintLayout)This will copy Constraints from the ConstraintLayout if it does not have parameters |
void |
This will copy Constraints from the ConstraintSet |
void |
removeAttribute(String attributeName)Remove the attribute |
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 |
setBarrierType(int id, int type)SEt tye type of barier |
void |
setColorValue(int viewId, String attributeName, int value)Set the value of an attribute of type color |
void |
setDimensionRatio(int viewId, String ratio)Constrains the views aspect ratio. |
void |
setEditorAbsoluteX(int viewId, int position) |
void |
setEditorAbsoluteY(int viewId, int position) |
void |
setElevation(int viewId, float elevation)Adjust the elevation of a view. |
void |
setFloatValue(int viewId, String attributeName, float value)Set the value of an attribute of type float |
void |
setForceId(boolean forceId)Enforce id are required for all ConstraintLayout children to use ConstraintSet. default = true; |
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. if the dimension behaviour is set to MATCH_CONSTRAINT. |
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 |
setIntValue(int viewId, String attributeName, int value)Set the value of an attribute of type int |
void |
setLayoutWrapBehavior(int viewId, int behavior)Sets the wrap behavior of the widget in the parent's wrap computation |
void |
setMargin(int viewId, int anchor, int value)Sets the margin. |
void |
setReferencedIds(int id, int[] referenced)sets the reference id's of a barrier. |
void |
setRotation(int viewId, float rotation)Adjust the post-layout rotation about the Z axis of a view. |
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 |
setStateLabels(String types)Set the types associated with this ConstraintSet The types mechanism allows you to tag the constraint set with a series of string to define properties of a ConstraintSet |
void |
setStateLabelsList(String[] types)Set the types associated with this ConstraintSet The types mechanism allows you to tag the constraint set with a series of string to define properties of a ConstraintSet |
void |
setStringValue(int viewId, String attributeName, String value)Set the value of an attribute of type string |
void |
setTransformPivot(Set X,Y location of the pivot point around which the view will rotate and scale. use Float.NaN to clear the pivot value. |
void |
setTransformPivotX(int viewId, 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. |
void |
setTransformPivotY(int viewId, 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. |
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 |
setValidateOnParse(boolean validate)If true perform validation checks when parsing ConstraintSets This will slow down parsing and should only be used for debugging |
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. in a chain, if the dimension behaviour is set to MATCH_CONSTRAINT |
void |
setVerticalWeight(int viewId, 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 |
void |
setVisibility(int viewId, int visibility)Adjust the visibility of a view. |
void |
setVisibilityMode(int viewId, int visibilityMode)ConstraintSet will not setVisibility. |
void |
writeState(Writer writer, ConstraintLayout layout, int flags)Write the state to a Writer |
Constants
CHAIN_SPREAD_INSIDE
public static final int CHAIN_SPREAD_INSIDE = 1
Chain spread inside style
CIRCLE_REFERENCE
public static final int CIRCLE_REFERENCE = 8
Circle reference from a view.
END
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
public static final int GONE = 8
This view is gone, and will not take any space for layout purposes. Use with setVisibility and
android:visibility.
HORIZONTAL_GUIDELINE
public static final int HORIZONTAL_GUIDELINE = 0
Used to create a horizontal create guidelines.
INVISIBLE
public static final int INVISIBLE = 4
This view is invisible, but it still takes up space for layout purposes. Use with setVisibility and
android:visibility.
MATCH_CONSTRAINT
public static final int MATCH_CONSTRAINT = 0
Dimension will be controlled by constraints
MATCH_CONSTRAINT_SPREAD
public static final int MATCH_CONSTRAINT_SPREAD = 0
Calculate the size of a view in 0 dp by reducing the constrains gaps as much as possible
MATCH_CONSTRAINT_WRAP
public static final int MATCH_CONSTRAINT_WRAP = 1
How to calculate the size of a view in 0 dp by using its wrap_content size
PARENT_ID
public static final int PARENT_ID = 0
References the id of the parent. Used in:
START
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
UNSET
public static final int UNSET = -1
Used to indicate a parameter is cleared or not set
VERTICAL_GUIDELINE
public static final int VERTICAL_GUIDELINE = 1
Used to create a vertical create guidelines. see create
VISIBLE
public static final int VISIBLE = 0
This view is visible. Use with setVisibility and
android:visibility.
WRAP_CONTENT
public static final int WRAP_CONTENT = -2
Dimension will set by the view's content
Public fields
Public constructors
Public methods
addColorAttributes
public void addColorAttributes(String[] attributeName)
Add attribute of type Color
| Parameters | |
|---|---|
String[] attributeName |
addFloatAttributes
public void addFloatAttributes(String[] attributeName)
Add attribute of type float
| Parameters | |
|---|---|
String[] attributeName |
addIntAttributes
public void addIntAttributes(String[] attributeName)
Add attribute of type Int
| Parameters | |
|---|---|
String[] attributeName |
addStringAttributes
public void addStringAttributes(String[] attributeName)
Add attribute of type string
| Parameters | |
|---|---|
String[] attributeName |
addToHorizontalChain
public void addToHorizontalChain(int viewId, int leftId, int rightId)
Adds a view to a horizontal chain.
| Parameters | |
|---|---|
int viewId |
view to add |
int leftId |
view in chain to the left |
int rightId |
view in chain to the right |
addToHorizontalChainRTL
public void addToHorizontalChainRTL(int viewId, int leftId, int rightId)
Adds a view to a horizontal chain.
| Parameters | |
|---|---|
int viewId |
view to add |
int leftId |
view to the start side |
int rightId |
view to the end side |
addToVerticalChain
public void addToVerticalChain(int viewId, int topId, int bottomId)
Adds a view to a vertical chain.
| Parameters | |
|---|---|
int viewId |
view to add to a vertical chain |
int topId |
view above. |
int bottomId |
view below |
applyCustomAttributes
public void applyCustomAttributes(ConstraintLayout constraintLayout)
Apply custom attributes alone
| Parameters | |
|---|---|
ConstraintLayout constraintLayout |
applyDeltaFrom
public void applyDeltaFrom(ConstraintSet cs)
Get the delta form the ConstraintSet and aplly to this
| Parameters | |
|---|---|
ConstraintSet cs |
applyTo
public void applyTo(ConstraintLayout constraintLayout)
Apply the constraints to a ConstraintLayout.
| Parameters | |
|---|---|
ConstraintLayout constraintLayout |
to be modified |
applyToHelper
public void applyToHelper(
ConstraintHelper helper,
ConstraintWidget child,
ConstraintLayout.LayoutParams layoutParams,
SparseArray<ConstraintWidget> mapIdToWidget
)
Apply Layout to Helper widget
| Parameters | |
|---|---|
ConstraintHelper helper |
|
ConstraintWidget child |
|
ConstraintLayout.LayoutParams layoutParams |
|
SparseArray<ConstraintWidget> mapIdToWidget |
applyToLayoutParams
public void applyToLayoutParams(int id, ConstraintLayout.LayoutParams layoutParams)
Fill in a ConstraintLayout LayoutParam based on the id.
| Parameters | |
|---|---|
int id |
Id of the view |
ConstraintLayout.LayoutParams layoutParams |
LayoutParams to be filled |
applyToWithoutCustom
public void applyToWithoutCustom(ConstraintLayout constraintLayout)
Apply the constraints to a ConstraintLayout.
| Parameters | |
|---|---|
ConstraintLayout constraintLayout |
to be modified |
buildDelta
public static ConstraintSet.Constraint buildDelta(Context context, XmlPullParser parser)
Used to read a ConstraintDelta
| Parameters | |
|---|---|
Context context |
|
XmlPullParser parser |
| Returns | |
|---|---|
ConstraintSet.Constraint |
center
public 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. (for sides see: TOP, BOTTOM, START, END, LEFT, RIGHT) Note, sides must be all vertical or horizontal sides.
| Parameters | |
|---|---|
int centerID |
ID of the widget to be centered |
int firstID |
ID of the first widget to connect the left or top of the widget to |
int firstSide |
the side of the widget to connect to |
int firstMargin |
the connection margin |
int secondId |
the ID of the second widget to connect to right or top of the widget to |
int secondSide |
the side of the widget to connect to |
int secondMargin |
the connection margin |
float bias |
the ratio between two connections |
centerHorizontally
public void centerHorizontally(int viewId, int toView)
Centers the view horizontally relative to toView's position.
| Parameters | |
|---|---|
int viewId |
ID of view to center Horizontally |
int toView |
ID of view to center on (or in) |
centerHorizontally
public 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. (for sides see: START, END, LEFT, RIGHT)
| Parameters | |
|---|---|
int centerID |
ID of widget to be centered |
int leftId |
The Id of the widget on the left side |
int leftSide |
The side of the leftId widget to connect to |
int leftMargin |
The margin on the left side |
int rightId |
The Id of the widget on the right side |
int rightSide |
The side of the rightId widget to connect to |
int rightMargin |
The margin on the right side |
float bias |
The ratio of the space on the left vs. right sides 0.5 is centered (default) |
centerHorizontallyRtl
public void centerHorizontallyRtl(int viewId, int toView)
Centers the view horizontally relative to toView's position.
| Parameters | |
|---|---|
int viewId |
ID of view to center Horizontally |
int toView |
ID of view to center on (or in) |
centerHorizontallyRtl
public 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. (for sides see: START, END, LEFT, RIGHT)
| Parameters | |
|---|---|
int centerID |
ID of widget to be centered |
int startId |
The Id of the widget on the start side (left in non rtl languages) |
int startSide |
The side of the startId widget to connect to |
int startMargin |
The margin on the start side |
int endId |
The Id of the widget on the start side (left in non rtl languages) |
int endSide |
The side of the endId widget to connect to |
int endMargin |
The margin on the end side |
float bias |
The ratio of the space on the start vs end side 0.5 is centered (default) |
centerVertically
public void centerVertically(int viewId, int toView)
Centers the view vertically relative to toView's position.
| Parameters | |
|---|---|
int viewId |
ID of view to center Horizontally |
int toView |
ID of view to center on (or in) |
centerVertically
public 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. (for sides see: TOP, BOTTOM)
| Parameters | |
|---|---|
int centerID |
ID of widget to be centered |
int topId |
The Id of the widget on the top side |
int topSide |
The side of the leftId widget to connect to |
int topMargin |
The margin on the top side |
int bottomId |
The Id of the widget on the bottom side |
int bottomSide |
The side of the bottomId widget to connect to |
int bottomMargin |
The margin on the bottom side |
float bias |
The ratio of the space on the top vs. bottom sides 0.5 is centered (default) |
clear
public void clear(int viewId)
Remove all constraints from this view.
| Parameters | |
|---|---|
int viewId |
ID of view to remove all connections to |
clear
public void clear(int viewId, int anchor)
Remove a constraint from this view.
| Parameters | |
|---|---|
int viewId |
ID of view to center on (or in) |
int anchor |
the Anchor to remove constraint from |
clone
public void clone(ConstraintLayout constraintLayout)
Copy the layout parameters of a ConstraintLayout.
| Parameters | |
|---|---|
ConstraintLayout constraintLayout |
The ConstraintLayout to be copied |
clone
public void clone(Constraints constraints)
Copy the layout parameters of a ConstraintLayout.
| Parameters | |
|---|---|
Constraints constraints |
The ConstraintLayout to be copied |
clone
public void clone(ConstraintSet set)
Copy the constraints from a layout.
| Parameters | |
|---|---|
ConstraintSet set |
constraint set to copy |
clone
public void clone(Context context, int constraintLayoutId)
Copy the constraints from a layout.
| Parameters | |
|---|---|
Context context |
the context for the layout inflation |
int constraintLayoutId |
the id of the layout file |
connect
public void connect(int startID, int startSide, int endID, int endSide)
Create a constraint between two widgets. (for sides see: TOP, BOTTOM, START, END, LEFT, RIGHT, BASELINE)
| Parameters | |
|---|---|
int startID |
the ID of the widget to be constrained |
int startSide |
the side of the widget to constrain |
int endID |
the id of the widget to constrain to |
int endSide |
the side of widget to constrain to |
connect
public void connect(int startID, int startSide, int endID, int endSide, int margin)
Create a constraint between two widgets. (for sides see: TOP, BOTTOM, START, END, LEFT, RIGHT, BASELINE)
| Parameters | |
|---|---|
int startID |
the ID of the widget to be constrained |
int startSide |
the side of the widget to constrain |
int endID |
the id of the widget to constrain to |
int endSide |
the side of widget to constrain to |
int margin |
the margin to constrain (margin must be positive) |
constrainCircle
public void constrainCircle(int viewId, int id, int radius, float angle)
Constrain the view on a circle constraint
| Parameters | |
|---|---|
int viewId |
ID of the view we constrain |
int id |
ID of the view we constrain relative to |
int radius |
the radius of the circle in degrees |
float angle |
the angle |
constrainDefaultHeight
public void constrainDefaultHeight(int viewId, int height)
Sets how the height is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD. Default is spread.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust its matchConstraintDefaultHeight |
int height |
MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD |
constrainDefaultWidth
public void constrainDefaultWidth(int viewId, int width)
Sets how the width is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD. Default is spread.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust its matchConstraintDefaultWidth |
int width |
SPREAD or WRAP |
constrainHeight
public void constrainHeight(int viewId, int height)
Sets the height of the view. It can be a dimension, WRAP_CONTENT or MATCH_CONSTRAINT.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust its height |
int height |
the height of the view |
constrainMaxHeight
public 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 | |
|---|---|
int viewId |
ID of view to adjust it height |
int height |
the maximum height of the constraint |
constrainMaxWidth
public 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 | |
|---|---|
int viewId |
ID of view to adjust its max height |
int width |
the maximum width of the view |
constrainMinHeight
public 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 | |
|---|---|
int viewId |
ID of view to adjust its min height |
int height |
the minimum height of the view |
constrainMinWidth
public 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 | |
|---|---|
int viewId |
ID of view to adjust its min height |
int width |
the minimum width of the view |
constrainPercentHeight
public void constrainPercentHeight(int viewId, float percent)
Sets the height of the view as a percentage of the parent.
| Parameters | |
|---|---|
int viewId |
|
float percent |
constrainPercentWidth
public void constrainPercentWidth(int viewId, float percent)
Sets the width of the view as a percentage of the parent.
| Parameters | |
|---|---|
int viewId |
|
float percent |
constrainWidth
public void constrainWidth(int viewId, int width)
Sets the width of the view. It can be a dimension, WRAP_CONTENT or MATCH_CONSTRAINT.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust its width |
int width |
the width of the view |
constrainedHeight
public void constrainedHeight(int viewId, boolean constrained)
Sets how the height is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD. Default is spread.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust its matchConstraintDefaultHeight |
boolean constrained |
if true height will be constrained |
constrainedWidth
public void constrainedWidth(int viewId, boolean constrained)
Sets how the width is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD. Default is spread.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust its matchConstraintDefaultWidth |
boolean constrained |
if true with will be constrained |
create
public void create(int guidelineID, int orientation)
Creates a ConstraintLayout virtual object. Currently only horizontal or vertical GuideLines.
| Parameters | |
|---|---|
int guidelineID |
ID of guideline to create |
int orientation |
the Orientation of the guideline |
createBarrier
public void createBarrier(int id, int direction, int margin, int[] referenced)
Creates a ConstraintLayout Barrier object.
| Parameters | |
|---|---|
int id |
|
int direction |
Barrier.{LEFT,RIGHT,TOP,BOTTOM,START,END} |
int[] referenced |
createHorizontalChain
public void createHorizontalChain(
int leftId,
int leftSide,
int rightId,
int rightSide,
int[] chainIds,
float[] weights,
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: START, END, LEFT, RIGHT)
| Parameters | |
|---|---|
int leftId |
The id of the widget to connect to or PARENT_ID |
int leftSide |
the side of the start to connect to |
int rightId |
The id of the widget to connect to or PARENT_ID |
int rightSide |
the side of the right to connect to |
int[] chainIds |
The widgets in the chain |
float[] weights |
The weight to assign to each element in the chain or null |
int style |
The type of chain |
createHorizontalChainRtl
public 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. (for sides see: START, END, LEFT, RIGHT)
| Parameters | |
|---|---|
int startId |
The id of the widget to connect to or PARENT_ID |
int startSide |
the side of the start to connect to |
int endId |
The id of the widget to connect to or PARENT_ID |
int endSide |
the side of the end to connect to |
int[] chainIds |
The widgets in the chain |
float[] weights |
The weight to assign to each element in the chain or null |
int style |
The type of chain |
createVerticalChain
public 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. This operation sets all the related margins to 0.
| Parameters | |
|---|---|
int topId |
The id of the widget to connect to or PARENT_ID |
int topSide |
the side of the start to connect to |
int bottomId |
The id of the widget to connect to or PARENT_ID |
int bottomSide |
the side of the right to connect to |
int[] chainIds |
widgets to use as a chain |
float[] weights |
can be null |
int style |
set the style of the chain |
dump
public void dump(MotionScene scene, int[] ids)
Dump the contents
| Parameters | |
|---|---|
MotionScene scene |
|
int[] ids |
getApplyElevation
public boolean getApplyElevation(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) |
getCustomAttributeSet
public HashMap<String, ConstraintAttribute> getCustomAttributeSet()
getHeight
public int getHeight(int viewId)
Get the height set in the view
| Parameters | |
|---|---|
int viewId |
the id of the view |
| Returns | |
|---|---|
int |
return the height constraint of the view |
getParameters
public ConstraintSet.Constraint getParameters(int mId)
| Parameters | |
|---|---|
int mId |
| Returns | |
|---|---|
ConstraintSet.Constraint |
getReferencedIds
public int[] getReferencedIds(int id)
get the reference id's of a helper.
| Parameters | |
|---|---|
int id |
| Returns | |
|---|---|
int[] |
array of id's |
getStateLabels
public String[] getStateLabels()
Get the types associated with this ConstraintSet The types mechanism allows you to tag the constraint set with a series of string to define properties of a ConstraintSet
| Returns | |
|---|---|
String[] |
an array of type strings |
getVisibility
public int getVisibility(int viewId)
Get the visibility flag set in this view
| Parameters | |
|---|---|
int viewId |
the id of the view |
| Returns | |
|---|---|
int |
the visibility constraint for the view |
getVisibilityMode
public int getVisibilityMode(int viewId)
ConstraintSet will not setVisibility. VISIBILITY_MODE_IGNORE or VISIBILITY_MODE_NORMAL.
| Parameters | |
|---|---|
int viewId |
ID of view |
getWidth
public int getWidth(int viewId)
Get the width set in the view
| Parameters | |
|---|---|
int viewId |
the id of the view |
| Returns | |
|---|---|
int |
return the width constraint of the view |
isForceId
public boolean isForceId()
Enforce id are required for all ConstraintLayout children to use ConstraintSet. default = true;
isValidateOnParse
public boolean isValidateOnParse()
If true perform validation checks when parsing ConstraintSets This will slow down parsing and should only be used for debugging
| Returns | |
|---|---|
boolean |
validate |
load
public void load(Context context, XmlPullParser parser)
Load a constraint set from a constraintSet.xml file
| Parameters | |
|---|---|
Context context |
the context for the inflation |
XmlPullParser parser |
id of xml file in res/xml/ |
load
public void load(Context context, 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 | |
|---|---|
Context context |
the context for the inflation |
int resourceId |
id of xml file in res/xml/ |
matchesLabels
public boolean matchesLabels(String[] types)
Test if the list of strings matches labels defined on this constraintSet
| Parameters | |
|---|---|
String[] types |
list of types |
| Returns | |
|---|---|
boolean |
true if all types are in the labels |
parseColorAttributes
public void parseColorAttributes(ConstraintSet.Constraint set, String attributes)
Parse color
| Parameters | |
|---|---|
ConstraintSet.Constraint set |
|
String attributes |
parseFloatAttributes
public void parseFloatAttributes(ConstraintSet.Constraint set, String attributes)
Parse floats
| Parameters | |
|---|---|
ConstraintSet.Constraint set |
|
String attributes |
parseIntAttributes
public void parseIntAttributes(ConstraintSet.Constraint set, String attributes)
Parse int
| Parameters | |
|---|---|
ConstraintSet.Constraint set |
|
String attributes |
parseStringAttributes
public void parseStringAttributes(ConstraintSet.Constraint set, String attributes)
Parse string
| Parameters | |
|---|---|
ConstraintSet.Constraint set |
|
String attributes |
readFallback
public void readFallback(ConstraintLayout constraintLayout)
This will copy Constraints from the ConstraintLayout if it does not have parameters
| Parameters | |
|---|---|
ConstraintLayout constraintLayout |
readFallback
public void readFallback(ConstraintSet set)
This will copy Constraints from the ConstraintSet
| Parameters | |
|---|---|
ConstraintSet set |
removeAttribute
public void removeAttribute(String attributeName)
Remove the attribute
| Parameters | |
|---|---|
String attributeName |
removeFromHorizontalChain
public 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 | |
|---|---|
int viewId |
the view to be removed |
removeFromVerticalChain
public 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 | |
|---|---|
int viewId |
the view to be removed |
setAlpha
public void setAlpha(int viewId, float alpha)
Adjust the alpha of a view.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust the vertical |
float alpha |
the alpha |
setApplyElevation
public 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 | |
|---|---|
boolean apply |
true if this constraint set applies elevation to this view |
setBarrierType
public void setBarrierType(int id, int type)
SEt tye type of barier
| Parameters | |
|---|---|
int id |
|
int type |
setColorValue
public void setColorValue(int viewId, String attributeName, int value)
Set the value of an attribute of type color
| Parameters | |
|---|---|
int viewId |
|
String attributeName |
|
int value |
setDimensionRatio
public 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 | |
|---|---|
int viewId |
ID of view to constrain |
String ratio |
The ratio of the width to height (width / height) |
setElevation
public void setElevation(int viewId, float elevation)
Adjust the elevation of a view.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust the elevation |
float elevation |
the elevation |
setFloatValue
public void setFloatValue(int viewId, String attributeName, float value)
Set the value of an attribute of type float
| Parameters | |
|---|---|
int viewId |
|
String attributeName |
|
float value |
setForceId
public void setForceId(boolean forceId)
Enforce id are required for all ConstraintLayout children to use ConstraintSet. default = true;
| Parameters | |
|---|---|
boolean forceId |
setGoneMargin
public void setGoneMargin(int viewId, int anchor, int value)
Sets the gone margin.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust the margin on |
int anchor |
The side to adjust the margin on |
int value |
The new value for the margin |
setGuidelineBegin
public void setGuidelineBegin(int guidelineID, int margin)
Set the guideline's distance form the top or left edge.
| Parameters | |
|---|---|
int guidelineID |
ID of the guideline |
int margin |
the distance to the top or left edge |
setGuidelineEnd
public void setGuidelineEnd(int guidelineID, int margin)
Set a guideline's distance to end.
| Parameters | |
|---|---|
int guidelineID |
ID of the guideline |
int margin |
the margin to the right or bottom side of container |
setGuidelinePercent
public void setGuidelinePercent(int guidelineID, float ratio)
Set a Guideline's percent.
| Parameters | |
|---|---|
int guidelineID |
ID of the guideline |
float ratio |
the ratio between the gap on the left and right 0.0 is top/left 0.5 is middle |
setHorizontalBias
public void setHorizontalBias(int viewId, float bias)
Adjust the horizontal bias of the view (used with views constrained on left and right).
| Parameters | |
|---|---|
int viewId |
ID of view to adjust the horizontal |
float bias |
the new bias 0.5 is in the middle |
setHorizontalChainStyle
public void setHorizontalChainStyle(int viewId, 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 outCHAIN_SPREAD_INSIDE-- similar, but the endpoints of the chain will not be spread outCHAIN_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 | |
|---|---|
int viewId |
ID of view to adjust its HorizontalChainStyle |
int chainStyle |
the weight that we can use to distribute the horizontal space |
setHorizontalWeight
public 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 | |
|---|---|
int viewId |
ID of view to adjust its HorizontalWeight |
float weight |
the weight that we can use to distribute the horizontal space |
setIntValue
public void setIntValue(int viewId, String attributeName, int value)
Set the value of an attribute of type int
| Parameters | |
|---|---|
int viewId |
|
String attributeName |
|
int value |
setLayoutWrapBehavior
public void setLayoutWrapBehavior(int viewId, int behavior)
Sets the wrap behavior of the widget in the parent's wrap computation
setMargin
public void setMargin(int viewId, int anchor, int value)
Sets the margin.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust the margin on |
int anchor |
The side to adjust the margin on |
int value |
The new value for the margin |
setReferencedIds
public void setReferencedIds(int id, int[] referenced)
sets the reference id's of a barrier.
| Parameters | |
|---|---|
int id |
|
int[] referenced |
setRotation
public void setRotation(int viewId, float rotation)
Adjust the post-layout rotation about the Z axis of a view.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust th Z rotation |
float rotation |
the rotation about the X axis |
setRotationX
public void setRotationX(int viewId, float rotationX)
Adjust the post-layout rotation about the X axis of a view.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust th X rotation |
float rotationX |
the rotation about the X axis |
setRotationY
public void setRotationY(int viewId, float rotationY)
Adjust the post-layout rotation about the Y axis of a view.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust the Y rotation |
float rotationY |
the rotationY |
setScaleX
public void setScaleX(int viewId, float scaleX)
Adjust the post-layout scale in X of a view.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust the scale in X |
float scaleX |
the scale in X |
setScaleY
public void setScaleY(int viewId, float scaleY)
Adjust the post-layout scale in Y of a view.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust the scale in Y |
float scaleY |
the scale in Y |
setStateLabels
public void setStateLabels(String types)
Set the types associated with this ConstraintSet The types mechanism allows you to tag the constraint set with a series of string to define properties of a ConstraintSet
| Parameters | |
|---|---|
String types |
a comer separated array of strings. |
setStateLabelsList
public void setStateLabelsList(String[] types)
Set the types associated with this ConstraintSet The types mechanism allows you to tag the constraint set with a series of string to define properties of a ConstraintSet
| Parameters | |
|---|---|
String[] types |
a comer separated array of strings. |
setStringValue
public void setStringValue(int viewId, String attributeName, String value)
Set the value of an attribute of type string
setTransformPivot
public void setTransformPivot(
int viewId,
float transformPivotX,
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 | |
|---|---|
int viewId |
ID of view to adjust the transforms pivot point |
float transformPivotX |
X location of the pivot point. |
float transformPivotY |
Y location of the pivot point. |
setTransformPivotX
public void setTransformPivotX(int viewId, 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 | |
|---|---|
int viewId |
ID of view to adjust the transforms pivot point about X |
float transformPivotX |
X location of the pivot point. |
setTransformPivotY
public void setTransformPivotY(int viewId, 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 | |
|---|---|
int viewId |
ID of view to adjust the transforms pivot point about Y |
float transformPivotY |
Y location of the pivot point. |
setTranslation
public void setTranslation(int viewId, float translationX, float translationY)
Adjust the post-layout translation of a view.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust its translation in X &Y |
float translationX |
the translation in X |
float translationY |
the translation in Y |
setTranslationX
public void setTranslationX(int viewId, float translationX)
Adjust the post-layout X translation of a view.
| Parameters | |
|---|---|
int viewId |
ID of view to translate in X |
float translationX |
the translation in X |
setTranslationY
public void setTranslationY(int viewId, float translationY)
Adjust the post-layout Y translation of a view.
| Parameters | |
|---|---|
int viewId |
ID of view to to translate in Y |
float translationY |
the translation in Y |
setTranslationZ
public void setTranslationZ(int viewId, float translationZ)
Adjust the translation in Z of a view.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust |
float translationZ |
the translationZ |
setValidateOnParse
public void setValidateOnParse(boolean validate)
If true perform validation checks when parsing ConstraintSets This will slow down parsing and should only be used for debugging
| Parameters | |
|---|---|
boolean validate |
setVerticalBias
public void setVerticalBias(int viewId, float bias)
Adjust the vertical bias of the view (used with views constrained on left and right).
| Parameters | |
|---|---|
int viewId |
ID of view to adjust the vertical |
float bias |
the new bias 0.5 is in the middle |
setVerticalChainStyle
public 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
CHAIN_SPREAD-- the elements will be spread outCHAIN_SPREAD_INSIDE-- similar, but the endpoints of the chain will not be spread outCHAIN_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 | |
|---|---|
int viewId |
ID of view to adjust its VerticalChainStyle |
int chainStyle |
the weight that we can use to distribute the horizontal space |
setVerticalWeight
public void setVerticalWeight(int viewId, 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 | |
|---|---|
int viewId |
ID of view to adjust its VerticalWeight |
float weight |
the weight that we can use to distribute the vertical space |
setVisibility
public void setVisibility(int viewId, int visibility)
Adjust the visibility of a view.
| Parameters | |
|---|---|
int viewId |
ID of view to adjust the vertical |
int visibility |
the visibility |
setVisibilityMode
public void setVisibilityMode(int viewId, int visibilityMode)
ConstraintSet will not setVisibility. VISIBILITY_MODE_IGNORE or VISIBILITY_MODE_NORMAL.
| Parameters | |
|---|---|
int viewId |
ID of view |
int visibilityMode |
writeState
public void writeState(Writer writer, ConstraintLayout layout, int flags)
Write the state to a Writer
| Parameters | |
|---|---|
Writer writer |
|
ConstraintLayout layout |
|
int flags |
| Throws | |
|---|---|
java.io.IOException |