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
.
For details about Constraint behaviour see ConstraintLayout
.
It lets you create and save constraints, and apply them to an existing ConstraintLayout. ConstraintsSet can be created in various ways:
-
Manually
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 |
HORIZONTAL_GUIDELINE
Used to create a horizontal create guidelines. |
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. |
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 |
GONE
This view is gone, and will not take any space for layout purposes. |
public
static
final
int |
HORIZONTAL
The horizontal orientation. |
public
static
final
int |
INVISIBLE
This view is invisible, but it still takes up space for layout purposes. |
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
static
final
int |
VISIBLE
This view is visible. |
public
static
final
int |
WRAP_CONTENT
Dimension will set by the view's content |
Public constructors | |
---|---|
ConstraintSet()
|
Public methods | |
---|---|
void
|
addColorAttributes(String... attributeName)
|
void
|
addFloatAttributes(String... attributeName)
|
void
|
addIntAttributes(String... attributeName)
|
void
|
addStringAttributes(String... attributeName)
|
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
|
applyTo(ConstraintLayout constraintLayout)
Apply the constraints to a ConstraintLayout. |
void
|
applyToHelper(ConstraintHelper helper, ConstraintWidget child, ConstraintLayout.LayoutParams layoutParams,
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. |
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(Context context, int constraintLayoutId)
Copy the constraints from a layout. |
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
|
connect(int startID, int startSide, int endID, int endSide, int margin)
Create a constraint between two widgets. |
void
|
connect(int startID, int startSide, int endID, int endSide)
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
|
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(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. |
HashMap<String, ConstraintAttribute>
|
getCustomAttributeSet()
|
ConstraintSet.Constraint
|
getParameters(int mId)
|
boolean
|
isForceId()
Enforce id are required for all ConstraintLayout children to use ConstraintSet. |
void
|
load(Context context, int resourceId)
Load a constraint set from a constraintSet.xml file. |
void
|
load(Context context, XmlPullParser parser)
Load a constraint set from a constraintSet.xml file |
void
|
parseColorAttributes(ConstraintSet.Constraint set, String attributes)
|
void
|
parseFloatAttributes(ConstraintSet.Constraint set, String attributes)
|
void
|
parseIntAttributes(ConstraintSet.Constraint set, String attributes)
|
void
|
parseStringAttributes(ConstraintSet.Constraint set, String attributes)
|
void
|
readFallback(ConstraintLayout constraintLayout)
This will copy Constraints from the ConstraintLayout if it does not have parameters |
void
|
readFallback(ConstraintSet set)
This will copy Constraints from the ConstraintSet |
void
|
removeAttribute(String attributeName)
|
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)
|
void
|
setColorValue(int viewId, String attributeName, int value)
|
void
|
setDimensionRatio(int viewId, String ratio)
Constrains the views aspect ratio. |
void
|
setElevation(int viewId, float elevation)
Adjust the elevation of a view. |
void
|
setFloatValue(int viewId, String attributeName, float value)
|
void
|
setForceId(boolean forceId)
Enforce id are required for all ConstraintLayout children to use ConstraintSet. |
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
|
setIntValue(int viewId, String attributeName, int value)
|
void
|
setMargin(int viewId, int anchor, int value)
Sets the margin. |
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
|
setStringValue(int viewId, String attributeName, String value)
|
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 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. |
Inherited methods | |
---|---|
Constants
BASELINE
public static final int BASELINE
The baseline of the text in a view.
Constant Value: 5 (0x00000005)
BOTTOM
public static final int BOTTOM
The bottom side of a view.
Constant Value: 4 (0x00000004)
END
public static final 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)
HORIZONTAL_GUIDELINE
public static final int HORIZONTAL_GUIDELINE
Used to create a horizontal create guidelines.
Constant Value: 0 (0x00000000)
LEFT
public static final int LEFT
The left side of a view.
Constant Value: 1 (0x00000001)
MATCH_CONSTRAINT
public static final int MATCH_CONSTRAINT
Dimension will be controlled by constraints
Constant Value: 0 (0x00000000)
PARENT_ID
public static final int PARENT_ID
References the id of the parent. Used in:
Constant Value: 0 (0x00000000)
RIGHT
public static final int RIGHT
The right side of a view.
Constant Value: 2 (0x00000002)
START
public static final 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
public static final int TOP
The top of a view.
Constant Value: 3 (0x00000003)
UNSET
public static final int UNSET
Used to indicate a parameter is cleared or not set
Constant Value: -1 (0xffffffff)
VERTICAL_GUIDELINE
public static final int VERTICAL_GUIDELINE
Used to create a vertical create guidelines.
see create(int, int)
Constant Value: 1 (0x00000001)
Fields
CHAIN_PACKED
public static final int CHAIN_PACKED
Chain packed style
CHAIN_SPREAD
public static final int CHAIN_SPREAD
Chain spread style
CHAIN_SPREAD_INSIDE
public static final int CHAIN_SPREAD_INSIDE
Chain spread inside style
GONE
public static final int GONE
This view is gone, and will not take any space for layout
purposes. Use with setVisibility(int, int)
and android:visibility
.
HORIZONTAL
public static final int HORIZONTAL
The horizontal orientation.
INVISIBLE
public static final int INVISIBLE
This view is invisible, but it still takes up space for layout purposes.
Use with setVisibility(int, int)
and android:visibility
.
MATCH_CONSTRAINT_SPREAD
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
MATCH_CONSTRAINT_WRAP
public static final int MATCH_CONSTRAINT_WRAP
How to calculate the size of a view in 0 dp by using its wrap_content size
VERTICAL
public static final int VERTICAL
The vertical orientation.
VISIBLE
public static final int VISIBLE
This view is visible.
Use with setVisibility(int, int)
and android:visibility
.
WRAP_CONTENT
public static final int WRAP_CONTENT
Dimension will set by the view's content
Public constructors
ConstraintSet
public ConstraintSet ()
Public methods
addColorAttributes
public void addColorAttributes (String... attributeName)
Parameters | |
---|---|
attributeName |
String |
addFloatAttributes
public void addFloatAttributes (String... attributeName)
Parameters | |
---|---|
attributeName |
String |
addIntAttributes
public void addIntAttributes (String... attributeName)
Parameters | |
---|---|
attributeName |
String |
addStringAttributes
public void addStringAttributes (String... attributeName)
Parameters | |
---|---|
attributeName |
String |
addToHorizontalChain
public 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
public 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
public 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
|
applyCustomAttributes
public void applyCustomAttributes (ConstraintLayout constraintLayout)
Apply custom attributes alone
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,mapIdToWidget)
Apply Layout to Helper widget
applyToLayoutParams
public void applyToLayoutParams (int id, ConstraintLayout.LayoutParams layoutParams)
Fill in a ConstraintLayout LayoutParam based on the id.
Parameters | |
---|---|
id |
int : Id of the view |
layoutParams |
ConstraintLayout.LayoutParams : LayoutParams to be filled
|
applyToWithoutCustom
public void applyToWithoutCustom (ConstraintLayout constraintLayout)
Apply the constraints to a ConstraintLayout.
Parameters | |
---|---|
constraintLayout |
ConstraintLayout : to be modified
|
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: {@link #TOP, {@link #BOTTOM}, {@link #START, {@link #END}, {@link #LEFT, {@link #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
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: {@link #START, {@link #END}, {@link #LEFT, {@link #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)
|
centerHorizontally
public 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
public 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
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 | |
---|---|
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
public 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
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: {@link #TOP, {@link #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
public 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
public void clear (int viewId)
Remove all constraints from this view.
Parameters | |
---|---|
viewId |
int : ID of view to remove all connections to
|
clone
public 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
|
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 | |
---|---|
set |
ConstraintSet : constraint set to copy
|
connect
public void connect (int startID, int startSide, int endID, int endSide, int margin)
Create a constraint between two widgets. (for sides see: {@link #TOP, {@link #BOTTOM}, {@link #START, {@link #END}, {@link #LEFT, {@link #RIGHT}, {@link #BASELINE})
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 positive)
|
connect
public void connect (int startID, int startSide, int endID, int endSide)
Create a constraint between two widgets. (for sides see: {@link #TOP, {@link #BOTTOM}, {@link #START, {@link #END}, {@link #LEFT, {@link #RIGHT}, {@link #BASELINE})
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
|
constrainCircle
public void constrainCircle (int viewId, int id, int radius, float angle)
Constrain the view on a circle constraint
Parameters | |
---|---|
viewId |
int : ID of the view we constrain |
id |
int : ID of the view we constrain relative to |
radius |
int : the radius of the circle in degrees |
angle |
float : 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 | |
---|---|
viewId |
int : ID of view to adjust its matchConstraintDefaultHeight |
height |
int : 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 | |
---|---|
viewId |
int : ID of view to adjust its matchConstraintDefaultWidth |
width |
int : 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 | |
---|---|
viewId |
int : ID of view to adjust its height |
height |
int : 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 | |
---|---|
viewId |
int : ID of view to adjust it height |
height |
int : 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 | |
---|---|
viewId |
int : ID of view to adjust its max height |
width |
int : 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 | |
---|---|
viewId |
int : ID of view to adjust its min height |
height |
int : 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 | |
---|---|
viewId |
int : ID of view to adjust its min height |
width |
int : 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.
constrainPercentWidth
public void constrainPercentWidth (int viewId, float percent)
Sets the width of the view as a percentage of the parent.
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 | |
---|---|
viewId |
int : ID of view to adjust its width |
width |
int : the width of the view |
create
public 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
|
createBarrier
public void createBarrier (int id, int direction, int margin, int... referenced)
Creates a ConstraintLayout Barrier object.
Parameters | |
---|---|
direction |
int : Barrier.{LEFT,RIGHT,TOP,BOTTOM,START,END} |
margin |
int |
createHorizontalChain
public 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. (for sides see: {@link #START, {@link #END}, {@link #LEFT, {@link #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 |
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
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: {@link #START, {@link #END}, {@link #LEFT, {@link #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 |
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
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. (for sides see: {@link #TOP, {@link #BOTTOM})
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
public 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) |
getCustomAttributeSet
public HashMap<String, ConstraintAttribute> getCustomAttributeSet ()
Returns | |
---|---|
HashMap<String, ConstraintAttribute> |
getParameters
public ConstraintSet.Constraint getParameters (int mId)
Parameters | |
---|---|
mId |
int |
Returns | |
---|---|
ConstraintSet.Constraint |
isForceId
public boolean isForceId ()
Enforce id are required for all ConstraintLayout children to use ConstraintSet. default = true;
Returns | |
---|---|
boolean |
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 |
resourceId |
int : id of xml file in res/xml/
|
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 |
parser |
XmlPullParser : id of xml file in res/xml/
|
parseColorAttributes
public void parseColorAttributes (ConstraintSet.Constraint set, String attributes)
Parameters | |
---|---|
set |
ConstraintSet.Constraint |
attributes |
String |
parseFloatAttributes
public void parseFloatAttributes (ConstraintSet.Constraint set, String attributes)
Parameters | |
---|---|
set |
ConstraintSet.Constraint |
attributes |
String |
parseIntAttributes
public void parseIntAttributes (ConstraintSet.Constraint set, String attributes)
Parameters | |
---|---|
set |
ConstraintSet.Constraint |
attributes |
String |
parseStringAttributes
public void parseStringAttributes (ConstraintSet.Constraint set, String attributes)
Parameters | |
---|---|
set |
ConstraintSet.Constraint |
attributes |
String |
readFallback
public void readFallback (ConstraintLayout constraintLayout)
This will copy Constraints from the ConstraintLayout if it does not have parameters
readFallback
public void readFallback (ConstraintSet set)
This will copy Constraints from the ConstraintSet
removeAttribute
public void removeAttribute (String attributeName)
Parameters | |
---|---|
attributeName |
String |
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 | |
---|---|
viewId |
int : 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 | |
---|---|
viewId |
int : the view to be removed
|
setAlpha
public 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
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 | |
---|---|
viewId |
int |
apply |
boolean : true if this constraint set applies elevation to this view
|
setBarrierType
public void setBarrierType (int id, int type)
Parameters | |
---|---|
id |
int |
type |
int |
setColorValue
public void setColorValue (int viewId, String attributeName, int value)
Parameters | |
---|---|
viewId |
int |
attributeName |
String |
value |
int |
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 | |
---|---|
viewId |
int : ID of view to constrain |
ratio |
String : The ratio of the width to height (width / height)
|
setElevation
public 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
|
setFloatValue
public void setFloatValue (int viewId, String attributeName, float value)
Parameters | |
---|---|
viewId |
int |
attributeName |
String |
value |
float |
setForceId
public void setForceId (boolean forceId)
Enforce id are required for all ConstraintLayout children to use ConstraintSet. default = true;
setGoneMargin
public 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
public 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
public 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
public 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
public 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
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:
- -- 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
|
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 | |
---|---|
viewId |
int : ID of view to adjust its HorizontalWeight |
weight |
float : the weight that we can use to distribute the horizontal space
|
setIntValue
public void setIntValue (int viewId, String attributeName, int value)
Parameters | |
---|---|
viewId |
int |
attributeName |
String |
value |
int |
setMargin
public 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
|
setRotation
public void setRotation (int viewId, float rotation)
Adjust the post-layout rotation about the Z axis of a view.
Parameters | |
---|---|
viewId |
int : ID of view to adjust th Z rotation |
rotation |
float : 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 | |
---|---|
viewId |
int : ID of view to adjust th X rotation |
rotationX |
float : 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 | |
---|---|
viewId |
int : ID of view to adjust the Y rotation |
rotationY |
float : the rotationY
|
setScaleX
public 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
public 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
|
setStringValue
public void setStringValue (int viewId, String attributeName, String value)
Parameters | |
---|---|
viewId |
int |
attributeName |
String |
value |
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 | |
---|---|
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
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 | |
---|---|
viewId |
int : ID of view to adjust the transforms pivot point about X |
transformPivotX |
float : 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 | |
---|---|
viewId |
int : ID of view to adjust the transforms pivot point about Y |
transformPivotY |
float : 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 | |
---|---|
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
public 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
public 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
public 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
public 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
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
- -- 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
|
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 | |
---|---|
viewId |
int : ID of view to adjust its VerticalWeight |
weight |
float : 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 | |
---|---|
viewId |
int : ID of view to adjust the vertical |
visibility |
int : the visibility
|