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