ConstraintWidget
public class ConstraintWidget
Guideline |
Guideline |
HelperWidget |
HelperWidget class |
WidgetContainer |
A container of ConstraintWidget |
Barrier |
A Barrier takes multiple widgets |
ConstraintWidgetContainer |
A container of ConstraintWidget that can layout its children |
Flow |
Implements the Flow virtual layout. |
GridCore |
The Grid Helper in the Core library that helps to enable Grid in Compose |
Placeholder |
Simple VirtualLayout that center the first referenced widget onto itself. |
VirtualLayout |
Base class for Virtual layouts |
Implements a constraint Widget model supporting constraints relations between other widgets.
The widget has various anchors (i.e. Left, Top, Right, Bottom, representing their respective sides, as well as Baseline, Center_X and Center_Y). Connecting anchors from one widget to another represents a constraint relation between the two anchors; the LinearSystem will then be able to use this model to try to minimize the distances between connected anchors.
If opposite anchors are connected (e.g. Left and Right anchors), if they have the same strength, the widget will be equally pulled toward their respective target anchor positions; if the widget has a fixed size, this means that the widget will be centered between the two target anchors. If the widget's size is allowed to adjust, the size of the widget will change to be as large as necessary so that the widget's anchors and the target anchors' distances are zero.
Constraints are set by connecting a widget's anchor to another via the connect function.Summary
Nested types |
|---|
public enum ConstraintWidget.DimensionBehaviourDefine how the widget will resize |
Constants |
|
|---|---|
static final int |
ANCHOR_BASELINE = 4 |
static final int |
ANCHOR_BOTTOM = 3 |
static final int |
ANCHOR_LEFT = 0 |
static final int |
ANCHOR_RIGHT = 1 |
static final int |
ANCHOR_TOP = 2 |
static final int |
BOTH = 2 |
static final int |
CHAIN_PACKED = 2 |
static final int |
CHAIN_SPREAD = 0 |
static final int |
|
static final int |
DIRECT = 2 |
static final int |
GONE = 8 |
static final int |
HORIZONTAL = 0 |
static final int |
INVISIBLE = 4 |
static final int |
|
static final int |
|
static final int |
|
static final int |
|
static final int |
|
static final int |
SOLVER = 1 |
static final int |
UNKNOWN = -1 |
static final int |
VERTICAL = 1 |
static final int |
VISIBLE = 0 |
static final int |
|
static final int |
|
static final int |
|
static final int |
Public fields |
|
|---|---|
static float |
|
WidgetFrame |
|
ChainRun |
|
int |
|
boolean[] |
|
ConstraintAnchor |
|
ConstraintAnchor |
|
ConstraintAnchor |
|
float |
|
float |
|
int |
|
HorizontalWidgetRun |
|
boolean |
|
boolean |
|
ConstraintAnchor |
|
ConstraintAnchor[] |
|
ConstraintWidget.DimensionBehaviour[] |
|
int |
|
int |
|
int |
|
int |
|
int |
|
int |
|
float |
|
float |
|
ConstraintWidget |
|
int[] |
|
ConstraintAnchor |
|
ConstraintAnchor |
|
int |
|
VerticalWidgetRun |
|
float[] |
|
boolean |
|
WidgetRun[] |
|
String |
|
ChainRun |
|
int |
Protected fields |
|
|---|---|
ArrayList<ConstraintAnchor> |
|
int |
|
ConstraintWidget[] |
|
int |
|
int |
|
ConstraintWidget[] |
|
int |
|
int |
|
int |
|
int |
Public constructors |
|---|
|
Default constructor |
ConstraintWidget(String debugName) |
ConstraintWidget(int width, int height)Constructor |
ConstraintWidget(String debugName, int width, int height) |
ConstraintWidget(int x, int y, int width, int height)Constructor |
ConstraintWidget(String debugName, int x, int y, int width, int height) |
Public methods |
|
|---|---|
void |
addChildrenToSolverByDependency( |
void |
addToSolver(LinearSystem system, boolean optimize)Add this widget to the solver |
boolean |
Returns true if this widget should be used in a barrier |
void |
connect(Connect a given anchor of this widget to another anchor of a target widget |
void |
connect(ConstraintAnchor from, ConstraintAnchor to, int margin)Connect the given anchors together (the from anchor should be owned by this widget) |
void |
connect(Connect a given anchor of this widget to another anchor of a target widget |
void |
connectCircularConstraint(Set a circular constraint |
void |
copy( |
void |
createObjectVariables(LinearSystem system)Create all the system variables for this widget |
void |
|
void |
|
ConstraintAnchor |
getAnchor(ConstraintAnchor.Type anchorType)Given a type of anchor, returns the corresponding anchor. |
ArrayList<ConstraintAnchor> |
Return the array of anchors of this widget |
int |
Return the baseline distance relative to the top of the widget |
float |
getBiasPercent(int orientation)Return the percentage bias that is used when two opposite connections exist of the same strength in a particular orientation. |
int |
Return the bottom position of the widget |
Object |
Return the companion widget. |
int |
Accessor for the skip value |
String |
Returns the name of this widget (used for debug purposes) |
ConstraintWidget.DimensionBehaviour |
getDimensionBehaviour(int orientation)Get the widget's |
float |
Return the current ratio of this widget |
int |
Return the current side on which ratio will be applied |
boolean |
|
int |
Return the height of the widget |
float |
Return the horizontal percentage bias that is used when two opposite connections exist of the same strength. |
ConstraintWidget |
if in a horizontal chain return the left most widget in the chain. |
int |
get the chain starting from this widget to be packed. |
ConstraintWidget.DimensionBehaviour |
Accessor for the horizontal dimension behaviour |
int |
Returns all the horizontal margin of the widget. |
int |
|
int |
|
int |
getLeft()Return the left position of the widget (similar to |
int |
getLength(int orientation)Get a dimension of the widget in a particular orientation. |
int |
|
int |
|
int |
Return the minimum height of the widget |
int |
Return the minimum width of the widget |
ConstraintWidget |
getNextChainMember(int orientation)Return the next chain member if one exists |
int |
|
int |
|
ConstraintWidget |
Returns the parent of this widget if there is one |
ConstraintWidget |
getPreviousChainMember(int orientation)Return the previous chain member if one exists |
int |
getRight()Return the right position of the widget |
WidgetRun |
getRun(int orientation) |
void |
|
int |
getTop()Return the top position of the widget (similar to |
String |
getType()Returns the type string if set |
float |
Return the vertical percentage bias that is used when two opposite connections exist of the same strength. |
ConstraintWidget |
if in a vertical chain return the top most widget in the chain. |
int |
Set the chain starting from this widget to be packed. |
ConstraintWidget.DimensionBehaviour |
Accessor for the vertical dimension behaviour |
int |
Returns all the vertical margin of the widget |
int |
Returns the current visibility value for this widget |
int |
getWidth()Return the width of the widget |
int |
|
int |
getX()Return the x position of the widget, relative to its container |
int |
getY()Return the y position of the widget, relative to its container |
boolean |
Return true if this widget has a baseline |
boolean |
hasDanglingDimension(int orientation) |
boolean |
|
boolean |
|
boolean |
hasResolvedTargets(int orientation, int size) |
void |
immediateConnect(Immediate connection to an anchor without any checks. |
boolean |
Returns if this widget is animated. |
boolean |
Returns true if height is set to wrap_content |
boolean |
|
boolean |
isInBarrier(int orientation) |
boolean |
Test if you are in a Horizontal chain |
boolean |
|
boolean |
Test if you are in a vertical chain |
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
isRoot()Returns true if the widget is the root widget |
boolean |
|
boolean |
|
boolean |
|
boolean |
Returns true if width is set to wrap_content |
void |
|
void |
|
boolean |
oppositeDimensionDependsOn(int orientation) |
boolean |
|
void |
reset() |
void |
Reset all the constraints set on this widget |
void |
resetAnchor(ConstraintAnchor anchor)Reset the given anchor |
void |
Reset all connections |
void |
|
void |
resetSolverVariables(Cache cache)Reset the solver variables of the anchors |
void |
|
StringBuilder |
serialize(StringBuilder ret)Serialize the anchors for JSON5 output |
void |
setAnimated(boolean animated)Set if this widget is animated. |
void |
setBaselineDistance(int baseline)Set the baseline distance relative to the top of the widget |
void |
setCompanionWidget(Object companion)Set the companion widget. |
void |
setContainerItemSkip(int skip)Set the skip value for this widget. |
void |
setDebugName(String name)Set the debug name of this widget |
void |
setDebugSolverName(LinearSystem system, String name)Utility debug function. |
void |
setDimension(int w, int h)Set both width and height of the widget |
void |
setDimensionRatio(String ratio)Set the ratio of the widget |
void |
setDimensionRatio(float ratio, int dimensionRatioSide)Set the ratio of the widget The ratio will be applied if at least one of the dimension (width or height) is set to a behaviour of DimensionBehaviour.MATCH_CONSTRAINT -- the dimension's value will be set to the other dimension * ratio. |
void |
setFinalBaseline(int baselineValue) |
void |
setFinalFrame( |
void |
setFinalHorizontal(int x1, int x2) |
void |
setFinalLeft(int x1) |
void |
setFinalTop(int y1) |
void |
setFinalVertical(int y1, int y2) |
void |
setFrame(int start, int end, int orientation)Set the position+dimension of the widget based on starting/ending positions on one dimension. |
void |
setFrame(int left, int top, int right, int bottom)Set the position+dimension of the widget given left/top/right/bottom |
void |
setGoneMargin(ConstraintAnchor.Type type, int goneMargin)Set the margin to be used when connected to a widget with a visibility of GONE |
void |
setHasBaseline(boolean hasBaseline) |
void |
setHeight(int h)Set the height of the widget |
void |
setHeightWrapContent(boolean heightWrapContent)Keep track of wrap_content for height |
void |
setHorizontalBiasPercent(float horizontalBiasPercent)Set the horizontal bias percent to apply when we have two opposite constraints of equal strength |
void |
setHorizontalChainStyle(int horizontalChainStyle)Set the chain starting from this widget to be packed. |
void |
setHorizontalDimension(int left, int right)Set the positions for the horizontal dimension only |
void |
Set the widget's behaviour for the horizontal dimension |
void |
setHorizontalMatchStyle(Set the horizontal style when MATCH_CONSTRAINT is set |
void |
setHorizontalWeight(float horizontalWeight)Set the horizontal weight (only used in chains) |
void |
setInPlaceholder(boolean inPlaceholder) |
void |
setInVirtualLayout(boolean inVirtualLayout) |
void |
setLastMeasureSpec(int horizontal, int vertical) |
void |
setLength(int length, int orientation)Set the dimension of a widget in a particular orientation. |
void |
setMaxHeight(int maxHeight) |
void |
setMaxWidth(int maxWidth) |
void |
setMeasureRequested(boolean measureRequested) |
void |
setMinHeight(int h)Set the minimum height of the widget |
void |
setMinWidth(int w)Set the minimum width of the widget |
void |
setOffset(int x, int y)Set the offset of this widget relative to the root widget |
void |
setOrigin(int x, int y)Set both the origin in (x, y) of the widget, relative to its container |
void |
setParent(ConstraintWidget widget)Set the parent of this widget |
void |
Set the type of the widget (as a String) |
void |
setVerticalBiasPercent(float verticalBiasPercent)Set the vertical bias percent to apply when we have two opposite constraints of equal strength |
void |
setVerticalChainStyle(int verticalChainStyle)Set the chain starting from this widget to be packed. |
void |
setVerticalDimension(int top, int bottom)Set the positions for the vertical dimension only |
void |
Set the widget's behaviour for the vertical dimension |
void |
setVerticalMatchStyle(Set the vertical style when MATCH_CONSTRAINT is set |
void |
setVerticalWeight(float verticalWeight)Set the vertical weight (only used in chains) |
void |
setVisibility(int visibility)Set the visibility for this widget |
void |
setWidth(int w)Set the width of the widget |
void |
setWidthWrapContent(boolean widthWrapContent)Keep track of wrap_content for width |
void |
setWrapBehaviorInParent(int behavior) |
void |
setX(int x)Set the x position of the widget, relative to its container |
void |
setY(int y)Set the y position of the widget, relative to its container |
void |
setupDimensionRatio(Resolves the dimension ratio parameters (mResolvedDimensionRatioSide &mDimensionRatio) |
String |
toString()Returns a string representation of the ConstraintWidget |
void |
updateFromRuns(boolean updateHorizontal, boolean updateVertical) |
void |
updateFromSolver(LinearSystem system, boolean optimize)Update the widget from the values generated by the solver |
Protected methods |
|
|---|---|
int |
getRootX()Return the x position of the widget, relative to the root (without animation) |
int |
getRootY()Return the y position of the widget, relative to the root (without animation) |
void |
setInBarrier(int orientation, boolean value) |
Constants
MATCH_CONSTRAINT_RATIO_RESOLVED
public static final int MATCH_CONSTRAINT_RATIO_RESOLVED = 4
WRAP_BEHAVIOR_HORIZONTAL_ONLY
public static final int WRAP_BEHAVIOR_HORIZONTAL_ONLY = 1
Public fields
mListDimensionBehaviors
public ConstraintWidget.DimensionBehaviour[] mListDimensionBehaviors
Protected fields
mListNextMatchConstraintsWidget
protected ConstraintWidget[] mListNextMatchConstraintsWidget
Public constructors
ConstraintWidget
public ConstraintWidget(int width, int height)
Constructor
| Parameters | |
|---|---|
int width |
width of the layout |
int height |
height of the layout |
ConstraintWidget
public ConstraintWidget(int x, int y, int width, int height)
Constructor
| Parameters | |
|---|---|
int x |
x position |
int y |
y position |
int width |
width of the layout |
int height |
height of the layout |
ConstraintWidget
public ConstraintWidget(String debugName, int x, int y, int width, int height)
Public methods
addChildrenToSolverByDependency
public void addChildrenToSolverByDependency(
ConstraintWidgetContainer container,
LinearSystem system,
HashSet<ConstraintWidget> widgets,
int orientation,
boolean addSelf
)
addToSolver
public void addToSolver(LinearSystem system, boolean optimize)
Add this widget to the solver
| Parameters | |
|---|---|
LinearSystem system |
the solver we want to add the widget to |
boolean optimize |
true if |
allowedInBarrier
public boolean allowedInBarrier()
Returns true if this widget should be used in a barrier
connect
public void connect(
ConstraintAnchor.Type constraintFrom,
ConstraintWidget target,
ConstraintAnchor.Type constraintTo
)
Connect a given anchor of this widget to another anchor of a target widget
| Parameters | |
|---|---|
ConstraintAnchor.Type constraintFrom |
which anchor of this widget to connect from |
ConstraintWidget target |
the target widget |
ConstraintAnchor.Type constraintTo |
the target anchor on the target widget |
connect
public void connect(ConstraintAnchor from, ConstraintAnchor to, int margin)
Connect the given anchors together (the from anchor should be owned by this widget)
| Parameters | |
|---|---|
ConstraintAnchor from |
the anchor we are connecting from (of this widget) |
ConstraintAnchor to |
the anchor we are connecting to |
int margin |
how much margin we want to have |
connect
public void connect(
ConstraintAnchor.Type constraintFrom,
ConstraintWidget target,
ConstraintAnchor.Type constraintTo,
int margin
)
Connect a given anchor of this widget to another anchor of a target widget
| Parameters | |
|---|---|
ConstraintAnchor.Type constraintFrom |
which anchor of this widget to connect from |
ConstraintWidget target |
the target widget |
ConstraintAnchor.Type constraintTo |
the target anchor on the target widget |
int margin |
how much margin we want to keep as a minimum distance between the two anchors |
connectCircularConstraint
public void connectCircularConstraint(
ConstraintWidget target,
float angle,
int radius
)
Set a circular constraint
| Parameters | |
|---|---|
ConstraintWidget target |
the target widget we will use as the center of the circle |
float angle |
the angle (from 0 to 360) |
int radius |
the radius used |
copy
public void copy(
ConstraintWidget src,
HashMap<ConstraintWidget, ConstraintWidget> map
)
createObjectVariables
public void createObjectVariables(LinearSystem system)
Create all the system variables for this widget
getAnchor
public ConstraintAnchor getAnchor(ConstraintAnchor.Type anchorType)
Given a type of anchor, returns the corresponding anchor.
| Parameters | |
|---|---|
ConstraintAnchor.Type anchorType |
type of the anchor (LEFT, TOP, RIGHT, BOTTOM, BASELINE, CENTER_X, CENTER_Y) |
| Returns | |
|---|---|
ConstraintAnchor |
the matching anchor |
getAnchors
public ArrayList<ConstraintAnchor> getAnchors()
Return the array of anchors of this widget
| Returns | |
|---|---|
ArrayList<ConstraintAnchor> |
array of anchors |
getBaselineDistance
public int getBaselineDistance()
Return the baseline distance relative to the top of the widget
| Returns | |
|---|---|
int |
baseline |
getBiasPercent
public float getBiasPercent(int orientation)
Return the percentage bias that is used when two opposite connections exist of the same strength in a particular orientation.
| Parameters | |
|---|---|
int orientation |
Orientation |
| Returns | |
|---|---|
float |
Respective percentage bias. |
getBottom
public int getBottom()
Return the bottom position of the widget
| Returns | |
|---|---|
int |
bottom position of the widget |
getCompanionWidget
public Object getCompanionWidget()
Return the companion widget. Typically, this would be the real widget we represent with this instance of ConstraintWidget.
| Returns | |
|---|---|
Object |
the companion widget, if set. |
getContainerItemSkip
public int getContainerItemSkip()
Accessor for the skip value
| Returns | |
|---|---|
int |
skip value |
getDebugName
public String getDebugName()
Returns the name of this widget (used for debug purposes)
| Returns | |
|---|---|
String |
the debug name |
getDimensionBehaviour
public ConstraintWidget.DimensionBehaviour getDimensionBehaviour(int orientation)
Get the widget's DimensionBehaviour in an specific orientation.
| Returns | |
|---|---|
ConstraintWidget.DimensionBehaviour |
The |
getDimensionRatio
public float getDimensionRatio()
Return the current ratio of this widget
| Returns | |
|---|---|
float |
the dimension ratio (HORIZONTAL, VERTICAL, or UNKNOWN) |
getDimensionRatioSide
public int getDimensionRatioSide()
Return the current side on which ratio will be applied
| Returns | |
|---|---|
int |
HORIZONTAL, VERTICAL, or UNKNOWN |
getHeight
public int getHeight()
Return the height of the widget
| Returns | |
|---|---|
int |
height height |
getHorizontalBiasPercent
public float getHorizontalBiasPercent()
Return the horizontal percentage bias that is used when two opposite connections exist of the same strength.
| Returns | |
|---|---|
float |
horizontal percentage bias |
getHorizontalChainControlWidget
public ConstraintWidget getHorizontalChainControlWidget()
if in a horizontal chain return the left most widget in the chain.
| Returns | |
|---|---|
ConstraintWidget |
left most widget in chain or null |
getHorizontalChainStyle
public int getHorizontalChainStyle()
get the chain starting from this widget to be packed. The horizontal bias will control how elements of the chain are positioned.
| Returns | |
|---|---|
int |
Horizontal Chain Style |
getHorizontalDimensionBehaviour
public ConstraintWidget.DimensionBehaviour getHorizontalDimensionBehaviour()
Accessor for the horizontal dimension behaviour
| Returns | |
|---|---|
ConstraintWidget.DimensionBehaviour |
dimension behaviour |
getHorizontalMargin
public int getHorizontalMargin()
Returns all the horizontal margin of the widget.
getLeft
public int getLeft()
Return the left position of the widget (similar to getX)
| Returns | |
|---|---|
int |
left position of the widget |
getLength
public int getLength(int orientation)
Get a dimension of the widget in a particular orientation.
| Returns | |
|---|---|
int |
The dimension of the specified orientation. |
getMinHeight
public int getMinHeight()
Return the minimum height of the widget
| Returns | |
|---|---|
int |
minimum height |
getMinWidth
public int getMinWidth()
Return the minimum width of the widget
| Returns | |
|---|---|
int |
minimum width |
getNextChainMember
public ConstraintWidget getNextChainMember(int orientation)
Return the next chain member if one exists
| Parameters | |
|---|---|
int orientation |
HORIZONTAL or VERTICAL |
| Returns | |
|---|---|
ConstraintWidget |
the next chain member or null if we are the last chain element |
getParent
public ConstraintWidget getParent()
Returns the parent of this widget if there is one
| Returns | |
|---|---|
ConstraintWidget |
parent |
getPreviousChainMember
public ConstraintWidget getPreviousChainMember(int orientation)
Return the previous chain member if one exists
| Parameters | |
|---|---|
int orientation |
HORIZONTAL or VERTICAL |
| Returns | |
|---|---|
ConstraintWidget |
the previous chain member or null if we are the first chain element |
getRight
public int getRight()
Return the right position of the widget
| Returns | |
|---|---|
int |
right position of the widget |
getTop
public int getTop()
Return the top position of the widget (similar to getY)
| Returns | |
|---|---|
int |
top position of the widget |
getType
public String getType()
Returns the type string if set
| Returns | |
|---|---|
String |
type (null if not set) |
getVerticalBiasPercent
public float getVerticalBiasPercent()
Return the vertical percentage bias that is used when two opposite connections exist of the same strength.
| Returns | |
|---|---|
float |
vertical percentage bias |
getVerticalChainControlWidget
public ConstraintWidget getVerticalChainControlWidget()
if in a vertical chain return the top most widget in the chain.
| Returns | |
|---|---|
ConstraintWidget |
top most widget in chain or null |
getVerticalChainStyle
public int getVerticalChainStyle()
Set the chain starting from this widget to be packed. The vertical bias will control how elements of the chain are positioned.
getVerticalDimensionBehaviour
public ConstraintWidget.DimensionBehaviour getVerticalDimensionBehaviour()
Accessor for the vertical dimension behaviour
| Returns | |
|---|---|
ConstraintWidget.DimensionBehaviour |
dimension behaviour |
getVerticalMargin
public int getVerticalMargin()
Returns all the vertical margin of the widget
getVisibility
public int getVisibility()
Returns the current visibility value for this widget
| Returns | |
|---|---|
int |
the visibility (VISIBLE, INVISIBLE, or GONE) |
getWidth
public int getWidth()
Return the width of the widget
| Returns | |
|---|---|
int |
width width |
getX
public int getX()
Return the x position of the widget, relative to its container
| Returns | |
|---|---|
int |
x position |
getY
public int getY()
Return the y position of the widget, relative to its container
| Returns | |
|---|---|
int |
y position |
hasBaseline
public boolean hasBaseline()
Return true if this widget has a baseline
| Returns | |
|---|---|
boolean |
true if the widget has a baseline, false otherwise |
immediateConnect
public void immediateConnect(
ConstraintAnchor.Type startType,
ConstraintWidget target,
ConstraintAnchor.Type endType,
int margin,
int goneMargin
)
Immediate connection to an anchor without any checks.
| Parameters | |
|---|---|
ConstraintAnchor.Type startType |
The type of anchor on this widget |
ConstraintWidget target |
The target widget |
ConstraintAnchor.Type endType |
The type of anchor on the target widget |
int margin |
How much margin we want to keep as a minimum distance between the two anchors |
int goneMargin |
How much margin we want to keep if the target is set to |
isAnimated
public boolean isAnimated()
Returns if this widget is animated. Currently only affects gone behaviour
| Returns | |
|---|---|
boolean |
true if ConstraintWidget is used in Animation |
isHeightWrapContent
public boolean isHeightWrapContent()
Returns true if height is set to wrap_content
isInHorizontalChain
public boolean isInHorizontalChain()
Test if you are in a Horizontal chain
| Returns | |
|---|---|
boolean |
true if in a horizontal chain |
isInVerticalChain
public boolean isInVerticalChain()
Test if you are in a vertical chain
| Returns | |
|---|---|
boolean |
true if in a vertical chain |
isRoot
public boolean isRoot()
Returns true if the widget is the root widget
| Returns | |
|---|---|
boolean |
true if root widget, false otherwise |
isWidthWrapContent
public boolean isWidthWrapContent()
Returns true if width is set to wrap_content
oppositeDimensionDependsOn
public boolean oppositeDimensionDependsOn(int orientation)
resetAllConstraints
public void resetAllConstraints()
Reset all the constraints set on this widget
resetAnchor
public void resetAnchor(ConstraintAnchor anchor)
Reset the given anchor
| Parameters | |
|---|---|
ConstraintAnchor anchor |
the anchor we want to reset |
resetSolverVariables
public void resetSolverVariables(Cache cache)
Reset the solver variables of the anchors
serialize
public StringBuilder serialize(StringBuilder ret)
Serialize the anchors for JSON5 output
| Parameters | |
|---|---|
StringBuilder ret |
StringBuilder to be populated |
| Returns | |
|---|---|
StringBuilder |
the same string builder to alow chaining |
setAnimated
public void setAnimated(boolean animated)
Set if this widget is animated. Currently only affects gone behaviour
| Parameters | |
|---|---|
boolean animated |
if true the widget must be positioned correctly when not visible |
setBaselineDistance
public void setBaselineDistance(int baseline)
Set the baseline distance relative to the top of the widget
| Parameters | |
|---|---|
int baseline |
the distance of the baseline relative to the widget's top |
setCompanionWidget
public void setCompanionWidget(Object companion)
Set the companion widget. Typically, this would be the real widget we represent with this instance of ConstraintWidget.
setContainerItemSkip
public void setContainerItemSkip(int skip)
Set the skip value for this widget. This can be used when a widget is in a container, so that container can position the widget as if it was positioned further in the list of widgets. For example, with Table, this is used to skip empty cells (the widget after an empty cell will have a skip value of one)
setDebugSolverName
public void setDebugSolverName(LinearSystem system, String name)
Utility debug function. Sets the names of the anchors in the solver given a widget's name. The given name is used as a prefix, resulting in anchors' names of the form:
- {name}.left
- {name}.top
- {name}.right
- {name}.bottom
- {name}.baseline
| Parameters | |
|---|---|
LinearSystem system |
solver used |
String name |
name of the widget |
setDimension
public void setDimension(int w, int h)
Set both width and height of the widget
| Parameters | |
|---|---|
int w |
width |
int h |
height |
setDimensionRatio
public void setDimensionRatio(String ratio)
Set the ratio of the widget
| Parameters | |
|---|---|
String ratio |
given string of format [H|V],[float|x:y] or [float|x:y] |
setDimensionRatio
public void setDimensionRatio(float ratio, int dimensionRatioSide)
Set the ratio of the widget The ratio will be applied if at least one of the dimension (width or height) is set to a behaviour of DimensionBehaviour.MATCH_CONSTRAINT -- the dimension's value will be set to the other dimension * ratio.
| Parameters | |
|---|---|
float ratio |
A float value that describes W/H or H/W depending on the provided dimensionRatioSide |
int dimensionRatioSide |
The side the ratio should be calculated on, HORIZONTAL, VERTICAL, or UNKNOWN |
setFinalFrame
public void setFinalFrame(
int left,
int top,
int right,
int bottom,
int baseline,
int orientation
)
setFrame
public void setFrame(int start, int end, int orientation)
Set the position+dimension of the widget based on starting/ending positions on one dimension.
| Parameters | |
|---|---|
int start |
Left/Top side position of the widget. |
int end |
Right/Bottom side position of the widget. |
int orientation |
Orientation being set (HORIZONTAL/VERTICAL). |
setFrame
public void setFrame(int left, int top, int right, int bottom)
Set the position+dimension of the widget given left/top/right/bottom
| Parameters | |
|---|---|
int left |
left side position of the widget |
int top |
top side position of the widget |
int right |
right side position of the widget |
int bottom |
bottom side position of the widget |
setGoneMargin
public void setGoneMargin(ConstraintAnchor.Type type, int goneMargin)
Set the margin to be used when connected to a widget with a visibility of GONE
| Parameters | |
|---|---|
ConstraintAnchor.Type type |
the anchor to set the margin on |
int goneMargin |
the margin value to use |
setHeight
public void setHeight(int h)
Set the height of the widget
| Parameters | |
|---|---|
int h |
height |
setHeightWrapContent
public void setHeightWrapContent(boolean heightWrapContent)
Keep track of wrap_content for height
setHorizontalBiasPercent
public void setHorizontalBiasPercent(float horizontalBiasPercent)
Set the horizontal bias percent to apply when we have two opposite constraints of equal strength
| Parameters | |
|---|---|
float horizontalBiasPercent |
the percentage used |
setHorizontalChainStyle
public void setHorizontalChainStyle(int horizontalChainStyle)
Set the chain starting from this widget to be packed. The horizontal bias will control how elements of the chain are positioned.
| Parameters | |
|---|---|
int horizontalChainStyle |
(CHAIN_SPREAD, CHAIN_SPREAD_INSIDE, CHAIN_PACKED) |
setHorizontalDimension
public void setHorizontalDimension(int left, int right)
Set the positions for the horizontal dimension only
| Parameters | |
|---|---|
int left |
left side position of the widget |
int right |
right side position of the widget |
setHorizontalDimensionBehaviour
public void setHorizontalDimensionBehaviour(
ConstraintWidget.DimensionBehaviour behaviour
)
Set the widget's behaviour for the horizontal dimension
| Parameters | |
|---|---|
ConstraintWidget.DimensionBehaviour behaviour |
the horizontal dimension's behaviour |
setHorizontalMatchStyle
public void setHorizontalMatchStyle(
int horizontalMatchStyle,
int min,
int max,
float percent
)
Set the horizontal style when MATCH_CONSTRAINT is set
| Parameters | |
|---|---|
int horizontalMatchStyle |
MATCH_CONSTRAINT_SPREAD or MATCH_CONSTRAINT_WRAP |
int min |
minimum value |
int max |
maximum value |
float percent |
Percent width |
setHorizontalWeight
public void setHorizontalWeight(float horizontalWeight)
Set the horizontal weight (only used in chains)
| Parameters | |
|---|---|
float horizontalWeight |
Floating point value weight |
setLength
public void setLength(int length, int orientation)
Set the dimension of a widget in a particular orientation.
| Parameters | |
|---|---|
int length |
Size of the dimension. |
int orientation |
HORIZONTAL or VERTICAL |
setMinHeight
public void setMinHeight(int h)
Set the minimum height of the widget
| Parameters | |
|---|---|
int h |
minimum height |
setMinWidth
public void setMinWidth(int w)
Set the minimum width of the widget
| Parameters | |
|---|---|
int w |
minimum width |
setOffset
public void setOffset(int x, int y)
Set the offset of this widget relative to the root widget
| Parameters | |
|---|---|
int x |
horizontal offset |
int y |
vertical offset |
setOrigin
public void setOrigin(int x, int y)
Set both the origin in (x, y) of the widget, relative to its container
| Parameters | |
|---|---|
int x |
x position |
int y |
y position |
setParent
public void setParent(ConstraintWidget widget)
Set the parent of this widget
| Parameters | |
|---|---|
ConstraintWidget widget |
parent |
setType
public void setType(String type)
Set the type of the widget (as a String)
| Parameters | |
|---|---|
String type |
type of the widget |
setVerticalBiasPercent
public void setVerticalBiasPercent(float verticalBiasPercent)
Set the vertical bias percent to apply when we have two opposite constraints of equal strength
| Parameters | |
|---|---|
float verticalBiasPercent |
the percentage used |
setVerticalChainStyle
public void setVerticalChainStyle(int verticalChainStyle)
Set the chain starting from this widget to be packed. The vertical bias will control how elements of the chain are positioned.
| Parameters | |
|---|---|
int verticalChainStyle |
(CHAIN_SPREAD, CHAIN_SPREAD_INSIDE, CHAIN_PACKED) |
setVerticalDimension
public void setVerticalDimension(int top, int bottom)
Set the positions for the vertical dimension only
| Parameters | |
|---|---|
int top |
top side position of the widget |
int bottom |
bottom side position of the widget |
setVerticalDimensionBehaviour
public void setVerticalDimensionBehaviour(
ConstraintWidget.DimensionBehaviour behaviour
)
Set the widget's behaviour for the vertical dimension
| Parameters | |
|---|---|
ConstraintWidget.DimensionBehaviour behaviour |
the vertical dimension's behaviour |
setVerticalMatchStyle
public void setVerticalMatchStyle(
int verticalMatchStyle,
int min,
int max,
float percent
)
Set the vertical style when MATCH_CONSTRAINT is set
| Parameters | |
|---|---|
int verticalMatchStyle |
MATCH_CONSTRAINT_SPREAD or MATCH_CONSTRAINT_WRAP |
int min |
minimum value |
int max |
maximum value |
float percent |
Percent height |
setVerticalWeight
public void setVerticalWeight(float verticalWeight)
Set the vertical weight (only used in chains)
| Parameters | |
|---|---|
float verticalWeight |
Floating point value weight |
setVisibility
public void setVisibility(int visibility)
Set the visibility for this widget
| Parameters | |
|---|---|
int visibility |
either VISIBLE, INVISIBLE, or GONE |
setWidth
public void setWidth(int w)
Set the width of the widget
| Parameters | |
|---|---|
int w |
width |
setWidthWrapContent
public void setWidthWrapContent(boolean widthWrapContent)
Keep track of wrap_content for width
setX
public void setX(int x)
Set the x position of the widget, relative to its container
| Parameters | |
|---|---|
int x |
x position |
setY
public void setY(int y)
Set the y position of the widget, relative to its container
| Parameters | |
|---|---|
int y |
y position |
setupDimensionRatio
public void setupDimensionRatio(
boolean hParentWrapContent,
boolean vParentWrapContent,
boolean horizontalDimensionFixed,
boolean verticalDimensionFixed
)
Resolves the dimension ratio parameters (mResolvedDimensionRatioSide &mDimensionRatio)
| Parameters | |
|---|---|
boolean hParentWrapContent |
true if parent is in wrap content horizontally |
boolean vParentWrapContent |
true if parent is in wrap content vertically |
boolean horizontalDimensionFixed |
true if this widget horizontal dimension is fixed |
boolean verticalDimensionFixed |
true if this widget vertical dimension is fixed |
toString
public String toString()
Returns a string representation of the ConstraintWidget
| Returns | |
|---|---|
String |
string representation of the widget |
updateFromRuns
public void updateFromRuns(boolean updateHorizontal, boolean updateVertical)
updateFromSolver
public void updateFromSolver(LinearSystem system, boolean optimize)
Update the widget from the values generated by the solver
| Parameters | |
|---|---|
LinearSystem system |
the solver we get the values from. |
boolean optimize |
true if |
Protected methods
getRootX
protected int getRootX()
Return the x position of the widget, relative to the root (without animation)
| Returns | |
|---|---|
int |
x position |