ConstraintProperties
public
class
ConstraintProperties
extends Object
java.lang.Object | |
↳ | android.support.constraint.ConstraintProperties |
Added in 2.0
ConstraintProperties provides an easy to use api to update the layout params
of ConstraintLayout
children
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 |
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 |
Fields | |
---|---|
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 |
WRAP_CONTENT
Dimension will set by the view's content |
Public constructors | |
---|---|
ConstraintProperties(View view)
|
Public methods | |
---|---|
ConstraintProperties
|
addToHorizontalChain(int leftId, int rightId)
Adds the view to a horizontal chain. |
ConstraintProperties
|
addToHorizontalChainRTL(int leftId, int rightId)
Adds the view to a horizontal chain using RTL attributes. |
ConstraintProperties
|
addToVerticalChain(int topId, int bottomId)
Adds a view to a vertical chain. |
ConstraintProperties
|
alpha(float alpha)
Adjust the alpha of a view. |
void
|
apply()
|
ConstraintProperties
|
center(int firstID, int firstSide, int firstMargin, int secondId, int secondSide, int secondMargin, float bias)
Center view between the other two widgets. |
ConstraintProperties
|
centerHorizontally(int toView)
Centers the view horizontally relative to toView's position. |
ConstraintProperties
|
centerHorizontally(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. |
ConstraintProperties
|
centerHorizontallyRtl(int toView)
Centers the view horizontally relative to toView's position. |
ConstraintProperties
|
centerHorizontallyRtl(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. |
ConstraintProperties
|
centerVertically(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. |
ConstraintProperties
|
centerVertically(int toView)
Centers the view vertically relative to toView's position. |
ConstraintProperties
|
connect(int startSide, int endID, int endSide, int margin)
Create a constraint between two widgets. |
ConstraintProperties
|
constrainDefaultHeight(int height)
Sets how the height is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD. |
ConstraintProperties
|
constrainDefaultWidth(int width)
Sets how the width is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD. |
ConstraintProperties
|
constrainHeight(int height)
Sets the height of the view. |
ConstraintProperties
|
constrainMaxHeight(int height)
Sets the maximum height of the view. |
ConstraintProperties
|
constrainMaxWidth(int width)
Sets the maximum width of the view. |
ConstraintProperties
|
constrainMinHeight(int height)
Sets the minimum height of the view. |
ConstraintProperties
|
constrainMinWidth(int width)
Sets the minimum width of the view. |
ConstraintProperties
|
constrainWidth(int width)
Sets the width of the view. |
ConstraintProperties
|
dimensionRatio(String ratio)
Constrains the views aspect ratio. |
ConstraintProperties
|
elevation(float elevation)
Set the elevation of a view. |
ConstraintProperties
|
goneMargin(int anchor, int value)
Sets the gone margin. |
ConstraintProperties
|
horizontalBias(float bias)
Adjust the horizontal bias of the view (used with views constrained on left and right). |
ConstraintProperties
|
horizontalChainStyle(int chainStyle)
How the elements of the horizontal chain will be positioned. |
ConstraintProperties
|
horizontalWeight(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 |
ConstraintProperties
|
margin(int anchor, int value)
Sets the margin. |
ConstraintProperties
|
removeConstraints(int anchor)
Remove a constraint from this view. |
ConstraintProperties
|
removeFromHorizontalChain()
Removes a view from a vertical chain. |
ConstraintProperties
|
removeFromVerticalChain()
Removes a view from a vertical chain. |
ConstraintProperties
|
rotation(float rotation)
Adjust the post-layout rotation about the Z axis of a view. |
ConstraintProperties
|
rotationX(float rotationX)
Adjust the post-layout rotation about the X axis of a view. |
ConstraintProperties
|
rotationY(float rotationY)
Adjust the post-layout rotation about the Y axis of a view. |
ConstraintProperties
|
scaleX(float scaleX)
Adjust the post-layout scale in X of a view. |
ConstraintProperties
|
scaleY(float scaleY)
Adjust the post-layout scale in Y of a view. |
ConstraintProperties
|
transformPivot(float transformPivotX, float transformPivotY)
Set X and Y location of the pivot point around which the view will rotate and scale. |
ConstraintProperties
|
transformPivotX(float transformPivotX)
Set X location of the pivot point around which the view will rotate and scale. |
ConstraintProperties
|
transformPivotY(float transformPivotY)
Set Y location of the pivot point around which the view will rotate and scale. |
ConstraintProperties
|
translation(float translationX, float translationY)
Adjust the post-layout X and Y translation of a view. |
ConstraintProperties
|
translationX(float translationX)
Adjust the post-layout X translation of a view. |
ConstraintProperties
|
translationY(float translationY)
Adjust the post-layout Y translation of a view. |
ConstraintProperties
|
translationZ(float translationZ)
Adjust the post-layout translation in Z of a view. |
ConstraintProperties
|
verticalBias(float bias)
Adjust the vertical bias of the view (used with views constrained on left and right). |
ConstraintProperties
|
verticalChainStyle(int chainStyle)
How the elements of the vertical chain will be positioned. |
ConstraintProperties
|
verticalWeight(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 |
ConstraintProperties
|
visibility(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)
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.
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)
Fields
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
WRAP_CONTENT
public static final int WRAP_CONTENT
Dimension will set by the view's content
Public constructors
ConstraintProperties
public ConstraintProperties (View view)
Parameters | |
---|---|
view |
View |
Public methods
addToHorizontalChain
public ConstraintProperties addToHorizontalChain (int leftId, int rightId)
Adds the view to a horizontal chain.
Parameters | |
---|---|
leftId |
int : id of the view in chain to the left |
rightId |
int : id of the view in chain to the right |
Returns | |
---|---|
ConstraintProperties |
this |
addToHorizontalChainRTL
public ConstraintProperties addToHorizontalChainRTL (int leftId, int rightId)
Adds the view to a horizontal chain using RTL attributes.
Parameters | |
---|---|
leftId |
int : id of the view in chain to the left |
rightId |
int : id of the view in chain to the right |
Returns | |
---|---|
ConstraintProperties |
this |
addToVerticalChain
public ConstraintProperties addToVerticalChain (int topId, int bottomId)
Adds a view to a vertical chain.
Parameters | |
---|---|
topId |
int : view above. |
bottomId |
int : view below |
Returns | |
---|---|
ConstraintProperties |
this |
alpha
public ConstraintProperties alpha (float alpha)
Adjust the alpha of a view.
Parameters | |
---|---|
alpha |
float : the alpha |
Returns | |
---|---|
ConstraintProperties |
this |
apply
public void apply ()
center
public ConstraintProperties center (int firstID, int firstSide, int firstMargin, int secondId, int secondSide, int secondMargin, float bias)
Center view between the other two widgets.
Parameters | |
---|---|
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 |
Returns | |
---|---|
ConstraintProperties |
this |
centerHorizontally
public ConstraintProperties centerHorizontally (int toView)
Centers the view horizontally relative to toView's position.
Parameters | |
---|---|
toView |
int : ID of view to center on (or in) |
Returns | |
---|---|
ConstraintProperties |
this |
centerHorizontally
public ConstraintProperties centerHorizontally (int leftId, int leftSide, int leftMargin, int rightId, int rightSide, int rightMargin, float bias)
Centers the widget horizontally to the left and right side on another widgets sides.
Parameters | |
---|---|
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) |
Returns | |
---|---|
ConstraintProperties |
this |
centerHorizontallyRtl
public ConstraintProperties centerHorizontallyRtl (int toView)
Centers the view horizontally relative to toView's position.
Parameters | |
---|---|
toView |
int : ID of view to center on (or in) |
Returns | |
---|---|
ConstraintProperties |
this |
centerHorizontallyRtl
public ConstraintProperties centerHorizontallyRtl (int startId, int startSide, int startMargin, int endId, int endSide, int endMargin, float bias)
Centers the widgets horizontally to the left and right side on another widgets sides.
Parameters | |
---|---|
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) |
Returns | |
---|---|
ConstraintProperties |
this |
centerVertically
public ConstraintProperties centerVertically (int topId, int topSide, int topMargin, int bottomId, int bottomSide, int bottomMargin, float bias)
Centers the widgets Vertically to the top and bottom side on another widgets sides.
Parameters | |
---|---|
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) |
Returns | |
---|---|
ConstraintProperties |
this |
centerVertically
public ConstraintProperties centerVertically (int toView)
Centers the view vertically relative to toView's position.
Parameters | |
---|---|
toView |
int : ID of view to center on (or in) |
Returns | |
---|---|
ConstraintProperties |
this |
connect
public ConstraintProperties connect (int startSide, int endID, int endSide, int margin)
Create a constraint between two widgets.
Parameters | |
---|---|
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)
|
Returns | |
---|---|
ConstraintProperties |
constrainDefaultHeight
public ConstraintProperties constrainDefaultHeight (int height)
Sets how the height is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD. Default is spread.
Parameters | |
---|---|
height |
int : MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD |
Returns | |
---|---|
ConstraintProperties |
this |
constrainDefaultWidth
public ConstraintProperties constrainDefaultWidth (int width)
Sets how the width is calculated ether MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD. Default is spread.
Parameters | |
---|---|
width |
int : MATCH_CONSTRAINT_WRAP or MATCH_CONSTRAINT_SPREAD |
Returns | |
---|---|
ConstraintProperties |
this |
constrainHeight
public ConstraintProperties constrainHeight (int height)
Sets the height of the view.
Parameters | |
---|---|
height |
int : the height of the view |
Returns | |
---|---|
ConstraintProperties |
this |
constrainMaxHeight
public ConstraintProperties constrainMaxHeight (int height)
Sets the maximum height of the view. It is a dimension, It is only applicable if height is #MATCH_CONSTRAINT}.
Parameters | |
---|---|
height |
int : the maximum height of the view |
Returns | |
---|---|
ConstraintProperties |
this |
constrainMaxWidth
public ConstraintProperties constrainMaxWidth (int width)
Sets the maximum width of the view. It is a dimension, It is only applicable if height is #MATCH_CONSTRAINT}.
Parameters | |
---|---|
width |
int : the maximum width of the view |
Returns | |
---|---|
ConstraintProperties |
this |
constrainMinHeight
public ConstraintProperties constrainMinHeight (int height)
Sets the minimum height of the view. It is a dimension, It is only applicable if height is #MATCH_CONSTRAINT}.
Parameters | |
---|---|
height |
int : the minimum height of the view |
Returns | |
---|---|
ConstraintProperties |
this |
constrainMinWidth
public ConstraintProperties constrainMinWidth (int width)
Sets the minimum width of the view. It is a dimension, It is only applicable if height is #MATCH_CONSTRAINT}.
Parameters | |
---|---|
width |
int : the minimum width of the view |
Returns | |
---|---|
ConstraintProperties |
this |
constrainWidth
public ConstraintProperties constrainWidth (int width)
Sets the width of the view.
Parameters | |
---|---|
width |
int : the width of the view |
Returns | |
---|---|
ConstraintProperties |
this |
dimensionRatio
public ConstraintProperties dimensionRatio (String ratio)
Constrains the views aspect ratio. For Example a HD screen is 16 by 9 = 16/(float)9 = 1.777f.
Parameters | |
---|---|
ratio |
String : The ratio of the width to height (width / height) |
Returns | |
---|---|
ConstraintProperties |
this |
elevation
public ConstraintProperties elevation (float elevation)
Set the elevation of a view.
Parameters | |
---|---|
elevation |
float : the elevation |
Returns | |
---|---|
ConstraintProperties |
this |
goneMargin
public ConstraintProperties goneMargin (int anchor, int value)
Sets the gone margin.
Parameters | |
---|---|
anchor |
int : The side to adjust the margin on |
value |
int : The new value for the margin |
Returns | |
---|---|
ConstraintProperties |
this |
horizontalBias
public ConstraintProperties horizontalBias (float bias)
Adjust the horizontal bias of the view (used with views constrained on left and right).
Parameters | |
---|---|
bias |
float : the new bias 0.5 is in the middle |
Returns | |
---|---|
ConstraintProperties |
this |
horizontalChainStyle
public ConstraintProperties horizontalChainStyle (int chainStyle)
How the elements of the horizontal chain will be positioned. If the dimension behaviour is set to MATCH_CONSTRAINT. The possible values are:
- CHAIN_SPREAD -- the elements will be spread out
- CHAIN_SPREAD_INSIDE -- similar, but the endpoints of the chain will not be spread out
- CHAIN_PACKED -- the elements of the chain will be packed together. The horizontal bias attribute of the child will then affect the positioning of the packed elements
Parameters | |
---|---|
chainStyle |
int : the weight that we can use to distribute the horizontal space |
Returns | |
---|---|
ConstraintProperties |
this |
horizontalWeight
public ConstraintProperties horizontalWeight (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 | |
---|---|
weight |
float : the weight that we can use to distribute the horizontal space |
Returns | |
---|---|
ConstraintProperties |
this |
margin
public ConstraintProperties margin (int anchor, int value)
Sets the margin.
Parameters | |
---|---|
anchor |
int : The side to adjust the margin on |
value |
int : The new value for the margin |
Returns | |
---|---|
ConstraintProperties |
this |
removeConstraints
public ConstraintProperties removeConstraints (int anchor)
Remove a constraint from this view.
Parameters | |
---|---|
anchor |
int : the Anchor to remove constraint from |
Returns | |
---|---|
ConstraintProperties |
this |
removeFromHorizontalChain
public ConstraintProperties removeFromHorizontalChain ()
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.
Returns | |
---|---|
ConstraintProperties |
this |
removeFromVerticalChain
public ConstraintProperties removeFromVerticalChain ()
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.
Returns | |
---|---|
ConstraintProperties |
this |
rotation
public ConstraintProperties rotation (float rotation)
Adjust the post-layout rotation about the Z axis of a view.
Parameters | |
---|---|
rotation |
float : the rotation about the Z axis |
Returns | |
---|---|
ConstraintProperties |
this |
rotationX
public ConstraintProperties rotationX (float rotationX)
Adjust the post-layout rotation about the X axis of a view.
Parameters | |
---|---|
rotationX |
float : the rotation about the X axis |
Returns | |
---|---|
ConstraintProperties |
this |
rotationY
public ConstraintProperties rotationY (float rotationY)
Adjust the post-layout rotation about the Y axis of a view.
Parameters | |
---|---|
rotationY |
float : the rotation about the Y axis |
Returns | |
---|---|
ConstraintProperties |
this |
scaleX
public ConstraintProperties scaleX (float scaleX)
Adjust the post-layout scale in X of a view.
Parameters | |
---|---|
scaleX |
float : the scale in X |
Returns | |
---|---|
ConstraintProperties |
this |
scaleY
public ConstraintProperties scaleY (float scaleY)
Adjust the post-layout scale in Y of a view.
Parameters | |
---|---|
scaleY |
float : the scale in Y |
Returns | |
---|---|
ConstraintProperties |
this |
transformPivot
public ConstraintProperties transformPivot (float transformPivotX, float transformPivotY)
Set X and Y location of the pivot point around which the view will rotate and scale.
Parameters | |
---|---|
transformPivotX |
float : X location of the pivot point. |
transformPivotY |
float : Y location of the pivot point. |
Returns | |
---|---|
ConstraintProperties |
this |
transformPivotX
public ConstraintProperties transformPivotX (float transformPivotX)
Set X location of the pivot point around which the view will rotate and scale.
Parameters | |
---|---|
transformPivotX |
float : X location of the pivot point. |
Returns | |
---|---|
ConstraintProperties |
this |
transformPivotY
public ConstraintProperties transformPivotY (float transformPivotY)
Set Y location of the pivot point around which the view will rotate and scale.
Parameters | |
---|---|
transformPivotY |
float : Y location of the pivot point. |
Returns | |
---|---|
ConstraintProperties |
this |
translation
public ConstraintProperties translation (float translationX, float translationY)
Adjust the post-layout X and Y translation of a view.
Parameters | |
---|---|
translationX |
float : the translation in X |
translationY |
float : the translation in Y |
Returns | |
---|---|
ConstraintProperties |
this |
translationX
public ConstraintProperties translationX (float translationX)
Adjust the post-layout X translation of a view.
Parameters | |
---|---|
translationX |
float : the translation in X |
Returns | |
---|---|
ConstraintProperties |
this |
translationY
public ConstraintProperties translationY (float translationY)
Adjust the post-layout Y translation of a view.
Parameters | |
---|---|
translationY |
float : the translation in Y |
Returns | |
---|---|
ConstraintProperties |
this |
translationZ
public ConstraintProperties translationZ (float translationZ)
Adjust the post-layout translation in Z of a view. This is the preferred way to adjust the shadow.
Parameters | |
---|---|
translationZ |
float : the translationZ |
Returns | |
---|---|
ConstraintProperties |
this |
verticalBias
public ConstraintProperties verticalBias (float bias)
Adjust the vertical bias of the view (used with views constrained on left and right).
Parameters | |
---|---|
bias |
float : the new bias 0.5 is in the middle |
Returns | |
---|---|
ConstraintProperties |
this |
verticalChainStyle
public ConstraintProperties verticalChainStyle (int chainStyle)
How the elements of the vertical chain will be positioned. in a chain, if the dimension behaviour is set to MATCH_CONSTRAINT
- CHAIN_SPREAD -- the elements will be spread out
- CHAIN_SPREAD_INSIDE -- similar, but the endpoints of the chain will not be spread out
- CHAIN_PACKED -- the elements of the chain will be packed together. The horizontal bias attribute of the child will then affect the positioning of the packed elements
Parameters | |
---|---|
chainStyle |
int : the weight that we can use to distribute the horizontal space |
Returns | |
---|---|
ConstraintProperties |
this |
verticalWeight
public ConstraintProperties verticalWeight (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 | |
---|---|
weight |
float : the weight that we can use to distribute the vertical space |
Returns | |
---|---|
ConstraintProperties |
this |
visibility
public ConstraintProperties visibility (int visibility)
Adjust the visibility of a view.
Parameters | |
---|---|
visibility |
int : the visibility (View.VISIBLE, View.INVISIBLE, View.GONE) |
Returns | |
---|---|
ConstraintProperties |
this |