Class ConstraintWidget
- java.lang.Object
-
- androidx.constraintlayout.core.widgets.ConstraintWidget
-
- Direct Known Subclasses:
Guideline,HelperWidget,WidgetContainer
public class ConstraintWidget extends java.lang.ObjectImplements 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
LinearSystemwill 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 theconnect(androidx.constraintlayout.core.widgets.ConstraintAnchor, androidx.constraintlayout.core.widgets.ConstraintAnchor, int)function.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConstraintWidget.DimensionBehaviourDefine how the widget will resize
-
Field Summary
-
Constructor Summary
Constructors Constructor Description ConstraintWidget()Default constructorConstraintWidget(int width, int height)ConstructorConstraintWidget(int x, int y, int width, int height)ConstructorConstraintWidget(java.lang.String debugName)ConstraintWidget(java.lang.String debugName, int width, int height)ConstraintWidget(java.lang.String debugName, int x, int y, int width, int height)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChildrenToSolverByDependency(ConstraintWidgetContainer container, LinearSystem system, java.util.HashSet<ConstraintWidget> widgets, int orientation, boolean addSelf)voidaddToSolver(LinearSystem system, boolean optimize)Add this widget to the solverbooleanallowedInBarrier()Returns true if this widget should be used in a barriervoidconnect(ConstraintAnchor.Type constraintFrom, ConstraintWidget target, ConstraintAnchor.Type constraintTo)Connect a given anchor of this widget to another anchor of a target widgetvoidconnect(ConstraintAnchor.Type constraintFrom, ConstraintWidget target, ConstraintAnchor.Type constraintTo, int margin)Connect a given anchor of this widget to another anchor of a target widgetvoidconnect(ConstraintAnchor from, ConstraintAnchor to, int margin)Connect the given anchors together (the from anchor should be owned by this widget)voidconnectCircularConstraint(ConstraintWidget target, float angle, int radius)Set a circular constraintvoidcopy(ConstraintWidget src, java.util.HashMap<ConstraintWidget,ConstraintWidget> map)voidcreateObjectVariables(LinearSystem system)Create all the system variables for this widgetvoidensureMeasureRequested()voidensureWidgetRuns()ConstraintAnchorgetAnchor(ConstraintAnchor.Type anchorType)Given a type of anchor, returns the corresponding anchor.java.util.ArrayList<ConstraintAnchor>getAnchors()Return the array of anchors of this widgetintgetBaselineDistance()Return the baseline distance relative to the top of the widgetfloatgetBiasPercent(int orientation)Return the percentage bias that is used when two opposite connections exist of the same strength in a particular orientation.intgetBottom()Return the bottom position of the widgetjava.lang.ObjectgetCompanionWidget()Return the companion widget.intgetContainerItemSkip()Accessor for the skip valuejava.lang.StringgetDebugName()Returns the name of this widget (used for debug purposes)ConstraintWidget.DimensionBehaviourgetDimensionBehaviour(int orientation)Get the widget'sConstraintWidget.DimensionBehaviourin an specific orientation.floatgetDimensionRatio()Return the current ratio of this widgetintgetDimensionRatioSide()Return the current side on which ratio will be appliedbooleangetHasBaseline()intgetHeight()Return the height of the widgetfloatgetHorizontalBiasPercent()Return the horizontal percentage bias that is used when two opposite connections exist of the same strength.ConstraintWidgetgetHorizontalChainControlWidget()if in a horizontal chain return the left most widget in the chain.intgetHorizontalChainStyle()get the chain starting from this widget to be packed.ConstraintWidget.DimensionBehaviourgetHorizontalDimensionBehaviour()Accessor for the horizontal dimension behaviourintgetHorizontalMargin()Returns all the horizontal margin of the widget.intgetLastHorizontalMeasureSpec()intgetLastVerticalMeasureSpec()intgetLeft()Return the left position of the widget (similar togetX())intgetLength(int orientation)Get a dimension of the widget in a particular orientation.intgetMaxHeight()intgetMaxWidth()intgetMinHeight()Return the minimum height of the widgetintgetMinWidth()Return the minimum width of the widgetConstraintWidgetgetNextChainMember(int orientation)Return the next chain member if one existsintgetOptimizerWrapHeight()intgetOptimizerWrapWidth()ConstraintWidgetgetParent()Returns the parent of this widget if there is oneConstraintWidgetgetPreviousChainMember(int orientation)Return the previous chain member if one existsintgetRight()Return the right position of the widgetprotected intgetRootX()Return the x position of the widget, relative to the root (without animation)protected intgetRootY()Return the y position of the widget, relative to the root (without animation)WidgetRungetRun(int orientation)voidgetSceneString(java.lang.StringBuilder ret)intgetTop()Return the top position of the widget (similar togetY())java.lang.StringgetType()Returns the type string if setfloatgetVerticalBiasPercent()Return the vertical percentage bias that is used when two opposite connections exist of the same strength.ConstraintWidgetgetVerticalChainControlWidget()if in a vertical chain return the top most widget in the chain.intgetVerticalChainStyle()Set the chain starting from this widget to be packed.ConstraintWidget.DimensionBehaviourgetVerticalDimensionBehaviour()Accessor for the vertical dimension behaviourintgetVerticalMargin()Returns all the vertical margin of the widgetintgetVisibility()Returns the current visibility value for this widgetintgetWidth()Return the width of the widgetintgetWrapBehaviorInParent()intgetX()Return the x position of the widget, relative to its containerintgetY()Return the y position of the widget, relative to its containerbooleanhasBaseline()Return true if this widget has a baselinebooleanhasDanglingDimension(int orientation)booleanhasDependencies()booleanhasDimensionOverride()booleanhasResolvedTargets(int orientation, int size)voidimmediateConnect(ConstraintAnchor.Type startType, ConstraintWidget target, ConstraintAnchor.Type endType, int margin, int goneMargin)Immediate connection to an anchor without any checks.booleanisAnimated()Returns if this widget is animated.booleanisHeightWrapContent()Returns true if height is set to wrap_contentbooleanisHorizontalSolvingPassDone()booleanisInBarrier(int orientation)booleanisInHorizontalChain()Test if you are in a Horizontal chainbooleanisInPlaceholder()booleanisInVerticalChain()Test if you are in a vertical chainbooleanisInVirtualLayout()booleanisMeasureRequested()booleanisResolvedHorizontally()booleanisResolvedVertically()booleanisRoot()Returns true if the widget is the root widgetbooleanisSpreadHeight()booleanisSpreadWidth()booleanisVerticalSolvingPassDone()booleanisWidthWrapContent()Returns true if width is set to wrap_contentvoidmarkHorizontalSolvingPassDone()voidmarkVerticalSolvingPassDone()booleanoppositeDimensionDependsOn(int orientation)booleanoppositeDimensionsTied()voidreset()voidresetAllConstraints()Reset all the constraints set on this widgetvoidresetAnchor(ConstraintAnchor anchor)Reset the given anchorvoidresetAnchors()Reset all connectionsvoidresetFinalResolution()voidresetSolverVariables(Cache cache)Reset the solver variables of the anchorsvoidresetSolvingPassFlag()java.lang.StringBuilderserialize(java.lang.StringBuilder ret)voidsetAnimated(boolean animated)Set if this widget is animated.voidsetBaselineDistance(int baseline)Set the baseline distance relative to the top of the widgetvoidsetCompanionWidget(java.lang.Object companion)Set the companion widget.voidsetContainerItemSkip(int skip)Set the skip value for this widget.voidsetDebugName(java.lang.String name)Set the debug name of this widgetvoidsetDebugSolverName(LinearSystem system, java.lang.String name)Utility debug function.voidsetDimension(int w, int h)Set both width and height of the widgetvoidsetDimensionRatio(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.voidsetDimensionRatio(java.lang.String ratio)Set the ratio of the widgetvoidsetFinalBaseline(int baselineValue)voidsetFinalFrame(int left, int top, int right, int bottom, int baseline, int orientation)voidsetFinalHorizontal(int x1, int x2)voidsetFinalLeft(int x1)voidsetFinalTop(int y1)voidsetFinalVertical(int y1, int y2)voidsetFrame(int start, int end, int orientation)Set the position+dimension of the widget based on starting/ending positions on one dimension.voidsetFrame(int left, int top, int right, int bottom)Set the position+dimension of the widget given left/top/right/bottomvoidsetGoneMargin(ConstraintAnchor.Type type, int goneMargin)Set the margin to be used when connected to a widget with a visibility of GONEvoidsetHasBaseline(boolean hasBaseline)voidsetHeight(int h)Set the height of the widgetvoidsetHeightWrapContent(boolean heightWrapContent)Keep track of wrap_content for heightvoidsetHorizontalBiasPercent(float horizontalBiasPercent)Set the horizontal bias percent to apply when we have two opposite constraints of equal strengthvoidsetHorizontalChainStyle(int horizontalChainStyle)Set the chain starting from this widget to be packed.voidsetHorizontalDimension(int left, int right)Set the positions for the horizontal dimension onlyvoidsetHorizontalDimensionBehaviour(ConstraintWidget.DimensionBehaviour behaviour)Set the widget's behaviour for the horizontal dimensionvoidsetHorizontalMatchStyle(int horizontalMatchStyle, int min, int max, float percent)Set the horizontal style when MATCH_CONSTRAINT is setvoidsetHorizontalWeight(float horizontalWeight)Set the horizontal weight (only used in chains)protected voidsetInBarrier(int orientation, boolean value)voidsetInPlaceholder(boolean inPlaceholder)voidsetInVirtualLayout(boolean inVirtualLayout)voidsetLastMeasureSpec(int horizontal, int vertical)voidsetLength(int length, int orientation)Set the dimension of a widget in a particular orientation.voidsetMaxHeight(int maxHeight)voidsetMaxWidth(int maxWidth)voidsetMeasureRequested(boolean measureRequested)voidsetMinHeight(int h)Set the minimum height of the widgetvoidsetMinWidth(int w)Set the minimum width of the widgetvoidsetOffset(int x, int y)Set the offset of this widget relative to the root widgetvoidsetOrigin(int x, int y)Set both the origin in (x, y) of the widget, relative to its containervoidsetParent(ConstraintWidget widget)Set the parent of this widgetvoidsetType(java.lang.String type)Set the type of the widget (as a String)voidsetupDimensionRatio(boolean hParentWrapContent, boolean vParentWrapContent, boolean horizontalDimensionFixed, boolean verticalDimensionFixed)Resolves the dimension ratio parameters (mResolvedDimensionRatioSide & mDimensionRatio)voidsetVerticalBiasPercent(float verticalBiasPercent)Set the vertical bias percent to apply when we have two opposite constraints of equal strengthvoidsetVerticalChainStyle(int verticalChainStyle)Set the chain starting from this widget to be packed.voidsetVerticalDimension(int top, int bottom)Set the positions for the vertical dimension onlyvoidsetVerticalDimensionBehaviour(ConstraintWidget.DimensionBehaviour behaviour)Set the widget's behaviour for the vertical dimensionvoidsetVerticalMatchStyle(int verticalMatchStyle, int min, int max, float percent)Set the vertical style when MATCH_CONSTRAINT is setvoidsetVerticalWeight(float verticalWeight)Set the vertical weight (only used in chains)voidsetVisibility(int visibility)Set the visibility for this widgetvoidsetWidth(int w)Set the width of the widgetvoidsetWidthWrapContent(boolean widthWrapContent)Keep track of wrap_content for widthvoidsetWrapBehaviorInParent(int behavior)voidsetX(int x)Set the x position of the widget, relative to its containervoidsetY(int y)Set the y position of the widget, relative to its containerjava.lang.StringtoString()Returns a string representation of the ConstraintWidgetvoidupdateFromRuns(boolean updateHorizontal, boolean updateVertical)voidupdateFromSolver(LinearSystem system, boolean optimize)Update the widget from the values generated by the solver
-
-
-
Field Detail
-
SOLVER
protected static final int SOLVER
- See Also:
- Constant Field Values
-
DIRECT
protected static final int DIRECT
- See Also:
- Constant Field Values
-
measured
public boolean measured
-
run
public WidgetRun[] run
-
horizontalChainRun
public ChainRun horizontalChainRun
-
verticalChainRun
public ChainRun verticalChainRun
-
mHorizontalRun
public HorizontalWidgetRun mHorizontalRun
-
mVerticalRun
public VerticalWidgetRun mVerticalRun
-
isTerminalWidget
public boolean[] isTerminalWidget
-
frame
public WidgetFrame frame
-
stringId
public java.lang.String stringId
-
MATCH_CONSTRAINT_SPREAD
public static final int MATCH_CONSTRAINT_SPREAD
- See Also:
- Constant Field Values
-
MATCH_CONSTRAINT_WRAP
public static final int MATCH_CONSTRAINT_WRAP
- See Also:
- Constant Field Values
-
MATCH_CONSTRAINT_PERCENT
public static final int MATCH_CONSTRAINT_PERCENT
- See Also:
- Constant Field Values
-
MATCH_CONSTRAINT_RATIO
public static final int MATCH_CONSTRAINT_RATIO
- See Also:
- Constant Field Values
-
MATCH_CONSTRAINT_RATIO_RESOLVED
public static final int MATCH_CONSTRAINT_RATIO_RESOLVED
- See Also:
- Constant Field Values
-
UNKNOWN
public static final int UNKNOWN
- See Also:
- Constant Field Values
-
HORIZONTAL
public static final int HORIZONTAL
- See Also:
- Constant Field Values
-
VERTICAL
public static final int VERTICAL
- See Also:
- Constant Field Values
-
BOTH
public static final int BOTH
- See Also:
- Constant Field Values
-
VISIBLE
public static final int VISIBLE
- See Also:
- Constant Field Values
-
INVISIBLE
public static final int INVISIBLE
- See Also:
- Constant Field Values
-
GONE
public static final int GONE
- See Also:
- Constant Field Values
-
CHAIN_SPREAD
public static final int CHAIN_SPREAD
- See Also:
- Constant Field Values
-
CHAIN_SPREAD_INSIDE
public static final int CHAIN_SPREAD_INSIDE
- See Also:
- Constant Field Values
-
CHAIN_PACKED
public static final int CHAIN_PACKED
- See Also:
- Constant Field Values
-
WRAP_BEHAVIOR_INCLUDED
public static final int WRAP_BEHAVIOR_INCLUDED
- See Also:
- Constant Field Values
-
WRAP_BEHAVIOR_HORIZONTAL_ONLY
public static final int WRAP_BEHAVIOR_HORIZONTAL_ONLY
- See Also:
- Constant Field Values
-
WRAP_BEHAVIOR_VERTICAL_ONLY
public static final int WRAP_BEHAVIOR_VERTICAL_ONLY
- See Also:
- Constant Field Values
-
WRAP_BEHAVIOR_SKIPPED
public static final int WRAP_BEHAVIOR_SKIPPED
- See Also:
- Constant Field Values
-
mHorizontalResolution
public int mHorizontalResolution
-
mVerticalResolution
public int mVerticalResolution
-
mMatchConstraintDefaultWidth
public int mMatchConstraintDefaultWidth
-
mMatchConstraintDefaultHeight
public int mMatchConstraintDefaultHeight
-
mResolvedMatchConstraintDefault
public int[] mResolvedMatchConstraintDefault
-
mMatchConstraintMinWidth
public int mMatchConstraintMinWidth
-
mMatchConstraintMaxWidth
public int mMatchConstraintMaxWidth
-
mMatchConstraintPercentWidth
public float mMatchConstraintPercentWidth
-
mMatchConstraintMinHeight
public int mMatchConstraintMinHeight
-
mMatchConstraintMaxHeight
public int mMatchConstraintMaxHeight
-
mMatchConstraintPercentHeight
public float mMatchConstraintPercentHeight
-
mIsWidthWrapContent
public boolean mIsWidthWrapContent
-
mIsHeightWrapContent
public boolean mIsHeightWrapContent
-
mLeft
public ConstraintAnchor mLeft
-
mTop
public ConstraintAnchor mTop
-
mRight
public ConstraintAnchor mRight
-
mBottom
public ConstraintAnchor mBottom
-
mBaseline
public ConstraintAnchor mBaseline
-
mCenter
public ConstraintAnchor mCenter
-
ANCHOR_LEFT
public static final int ANCHOR_LEFT
- See Also:
- Constant Field Values
-
ANCHOR_RIGHT
public static final int ANCHOR_RIGHT
- See Also:
- Constant Field Values
-
ANCHOR_TOP
public static final int ANCHOR_TOP
- See Also:
- Constant Field Values
-
ANCHOR_BOTTOM
public static final int ANCHOR_BOTTOM
- See Also:
- Constant Field Values
-
ANCHOR_BASELINE
public static final int ANCHOR_BASELINE
- See Also:
- Constant Field Values
-
mListAnchors
public ConstraintAnchor[] mListAnchors
-
mAnchors
protected java.util.ArrayList<ConstraintAnchor> mAnchors
-
mListDimensionBehaviors
public ConstraintWidget.DimensionBehaviour[] mListDimensionBehaviors
-
mParent
public ConstraintWidget mParent
-
mDimensionRatio
public float mDimensionRatio
-
mDimensionRatioSide
protected int mDimensionRatioSide
-
mX
protected int mX
-
mY
protected int mY
-
mOffsetX
protected int mOffsetX
-
mOffsetY
protected int mOffsetY
-
mMinWidth
protected int mMinWidth
-
mMinHeight
protected int mMinHeight
-
DEFAULT_BIAS
public static float DEFAULT_BIAS
-
mWeight
public float[] mWeight
-
mListNextMatchConstraintsWidget
protected ConstraintWidget[] mListNextMatchConstraintsWidget
-
mNextChainWidget
protected ConstraintWidget[] mNextChainWidget
-
horizontalGroup
public int horizontalGroup
-
verticalGroup
public int verticalGroup
-
-
Constructor Detail
-
ConstraintWidget
public ConstraintWidget()
Default constructor
-
ConstraintWidget
public ConstraintWidget(java.lang.String debugName)
-
ConstraintWidget
public ConstraintWidget(int x, int y, int width, int height)Constructor- Parameters:
x- x positiony- y positionwidth- width of the layoutheight- height of the layout
-
ConstraintWidget
public ConstraintWidget(java.lang.String debugName, int x, int y, int width, int height)
-
ConstraintWidget
public ConstraintWidget(int width, int height)Constructor- Parameters:
width- width of the layoutheight- height of the layout
-
ConstraintWidget
public ConstraintWidget(java.lang.String debugName, int width, int height)
-
-
Method Detail
-
getRun
public WidgetRun getRun(int orientation)
-
setFinalFrame
public void setFinalFrame(int left, int top, int right, int bottom, int baseline, int orientation)
-
setFinalLeft
public void setFinalLeft(int x1)
-
setFinalTop
public void setFinalTop(int y1)
-
resetSolvingPassFlag
public void resetSolvingPassFlag()
-
isHorizontalSolvingPassDone
public boolean isHorizontalSolvingPassDone()
-
isVerticalSolvingPassDone
public boolean isVerticalSolvingPassDone()
-
markHorizontalSolvingPassDone
public void markHorizontalSolvingPassDone()
-
markVerticalSolvingPassDone
public void markVerticalSolvingPassDone()
-
setFinalHorizontal
public void setFinalHorizontal(int x1, int x2)
-
setFinalVertical
public void setFinalVertical(int y1, int y2)
-
setFinalBaseline
public void setFinalBaseline(int baselineValue)
-
isResolvedHorizontally
public boolean isResolvedHorizontally()
-
isResolvedVertically
public boolean isResolvedVertically()
-
resetFinalResolution
public void resetFinalResolution()
-
ensureMeasureRequested
public void ensureMeasureRequested()
-
hasDependencies
public boolean hasDependencies()
-
hasDanglingDimension
public boolean hasDanglingDimension(int orientation)
-
hasResolvedTargets
public boolean hasResolvedTargets(int orientation, int size)
-
isInVirtualLayout
public boolean isInVirtualLayout()
-
setInVirtualLayout
public void setInVirtualLayout(boolean inVirtualLayout)
-
getMaxHeight
public int getMaxHeight()
-
getMaxWidth
public int getMaxWidth()
-
setMaxWidth
public void setMaxWidth(int maxWidth)
-
setMaxHeight
public void setMaxHeight(int maxHeight)
-
isSpreadWidth
public boolean isSpreadWidth()
-
isSpreadHeight
public boolean isSpreadHeight()
-
setHasBaseline
public void setHasBaseline(boolean hasBaseline)
-
getHasBaseline
public boolean getHasBaseline()
-
isInPlaceholder
public boolean isInPlaceholder()
-
setInPlaceholder
public void setInPlaceholder(boolean inPlaceholder)
-
setInBarrier
protected void setInBarrier(int orientation, boolean value)
-
isInBarrier
public boolean isInBarrier(int orientation)
-
setMeasureRequested
public void setMeasureRequested(boolean measureRequested)
-
isMeasureRequested
public boolean isMeasureRequested()
-
setWrapBehaviorInParent
public void setWrapBehaviorInParent(int behavior)
-
getWrapBehaviorInParent
public int getWrapBehaviorInParent()
-
getLastHorizontalMeasureSpec
public int getLastHorizontalMeasureSpec()
-
getLastVerticalMeasureSpec
public int getLastVerticalMeasureSpec()
-
setLastMeasureSpec
public void setLastMeasureSpec(int horizontal, int vertical)
-
reset
public void reset()
-
serialize
public java.lang.StringBuilder serialize(java.lang.StringBuilder ret)
-
oppositeDimensionDependsOn
public boolean oppositeDimensionDependsOn(int orientation)
-
oppositeDimensionsTied
public boolean oppositeDimensionsTied()
-
hasDimensionOverride
public boolean hasDimensionOverride()
-
ensureWidgetRuns
public void ensureWidgetRuns()
-
resetSolverVariables
public void resetSolverVariables(Cache cache)
Reset the solver variables of the anchors
-
isRoot
public boolean isRoot()
Returns true if the widget is the root widget- Returns:
- true if root widget, false otherwise
-
getParent
public ConstraintWidget getParent()
Returns the parent of this widget if there is one- Returns:
- parent
-
setParent
public void setParent(ConstraintWidget widget)
Set the parent of this widget- Parameters:
widget- parent
-
setWidthWrapContent
public void setWidthWrapContent(boolean widthWrapContent)
Keep track of wrap_content for width
-
isWidthWrapContent
public boolean isWidthWrapContent()
Returns true if width is set to wrap_content
-
setHeightWrapContent
public void setHeightWrapContent(boolean heightWrapContent)
Keep track of wrap_content for height
-
isHeightWrapContent
public boolean isHeightWrapContent()
Returns true if height is set to wrap_content
-
connectCircularConstraint
public void connectCircularConstraint(ConstraintWidget target, float angle, int radius)
Set a circular constraint- Parameters:
target- the target widget we will use as the center of the circleangle- the angle (from 0 to 360)radius- the radius used
-
getType
public java.lang.String getType()
Returns the type string if set- Returns:
- type (null if not set)
-
setType
public void setType(java.lang.String type)
Set the type of the widget (as a String)- Parameters:
type- type of the widget
-
setVisibility
public void setVisibility(int visibility)
Set the visibility for this widget- Parameters:
visibility- either VISIBLE, INVISIBLE, or GONE
-
getVisibility
public int getVisibility()
Returns the current visibility value for this widget- Returns:
- the visibility (VISIBLE, INVISIBLE, or GONE)
-
setAnimated
public void setAnimated(boolean animated)
Set if this widget is animated. Currently only affects gone behaviour- Parameters:
animated- if true the widget must be positioned correctly when not visible
-
isAnimated
public boolean isAnimated()
Returns if this widget is animated. Currently only affects gone behaviour- Returns:
- true if ConstraintWidget is used in Animation
-
getDebugName
public java.lang.String getDebugName()
Returns the name of this widget (used for debug purposes)- Returns:
- the debug name
-
setDebugName
public void setDebugName(java.lang.String name)
Set the debug name of this widget
-
setDebugSolverName
public void setDebugSolverName(LinearSystem system, java.lang.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:
system- solver usedname- name of the widget
-
createObjectVariables
public void createObjectVariables(LinearSystem system)
Create all the system variables for this widget
-
toString
public java.lang.String toString()
Returns a string representation of the ConstraintWidget- Overrides:
toStringin classjava.lang.Object- Returns:
- string representation of the widget
-
getX
public int getX()
Return the x position of the widget, relative to its container- Returns:
- x position
-
getY
public int getY()
Return the y position of the widget, relative to its container- Returns:
- y position
-
getWidth
public int getWidth()
Return the width of the widget- Returns:
- width width
-
getOptimizerWrapWidth
public int getOptimizerWrapWidth()
-
getOptimizerWrapHeight
public int getOptimizerWrapHeight()
-
getHeight
public int getHeight()
Return the height of the widget- Returns:
- height height
-
getLength
public int getLength(int orientation)
Get a dimension of the widget in a particular orientation.- Returns:
- The dimension of the specified orientation.
-
getRootX
protected int getRootX()
Return the x position of the widget, relative to the root (without animation)- Returns:
- x position
-
getRootY
protected int getRootY()
Return the y position of the widget, relative to the root (without animation)
-
getMinWidth
public int getMinWidth()
Return the minimum width of the widget- Returns:
- minimum width
-
getMinHeight
public int getMinHeight()
Return the minimum height of the widget- Returns:
- minimum height
-
getLeft
public int getLeft()
Return the left position of the widget (similar togetX())- Returns:
- left position of the widget
-
getTop
public int getTop()
Return the top position of the widget (similar togetY())- Returns:
- top position of the widget
-
getRight
public int getRight()
Return the right position of the widget- Returns:
- right position of the widget
-
getBottom
public int getBottom()
Return the bottom position of the widget- Returns:
- bottom position of the widget
-
getHorizontalMargin
public int getHorizontalMargin()
Returns all the horizontal margin of the widget.
-
getVerticalMargin
public int getVerticalMargin()
Returns all the vertical margin of the widget
-
getHorizontalBiasPercent
public float getHorizontalBiasPercent()
Return the horizontal percentage bias that is used when two opposite connections exist of the same strength.- Returns:
- horizontal percentage bias
-
getVerticalBiasPercent
public float getVerticalBiasPercent()
Return the vertical percentage bias that is used when two opposite connections exist of the same strength.- Returns:
- vertical percentage bias
-
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:
orientation- OrientationHORIZONTAL/VERTICAL.- Returns:
- Respective percentage bias.
-
hasBaseline
public boolean hasBaseline()
Return true if this widget has a baseline- Returns:
- true if the widget has a baseline, false otherwise
-
getBaselineDistance
public int getBaselineDistance()
Return the baseline distance relative to the top of the widget- Returns:
- baseline
-
getCompanionWidget
public java.lang.Object getCompanionWidget()
Return the companion widget. Typically, this would be the real widget we represent with this instance of ConstraintWidget.- Returns:
- the companion widget, if set.
-
getAnchors
public java.util.ArrayList<ConstraintAnchor> getAnchors()
Return the array of anchors of this widget- Returns:
- array of anchors
-
setX
public void setX(int x)
Set the x position of the widget, relative to its container- Parameters:
x- x position
-
setY
public void setY(int y)
Set the y position of the widget, relative to its container- Parameters:
y- y position
-
setOrigin
public void setOrigin(int x, int y)Set both the origin in (x, y) of the widget, relative to its container- Parameters:
x- x positiony- y position
-
setOffset
public void setOffset(int x, int y)Set the offset of this widget relative to the root widget- Parameters:
x- horizontal offsety- vertical offset
-
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:
type- the anchor to set the margin ongoneMargin- the margin value to use
-
setWidth
public void setWidth(int w)
Set the width of the widget- Parameters:
w- width
-
setHeight
public void setHeight(int h)
Set the height of the widget- Parameters:
h- height
-
setLength
public void setLength(int length, int orientation)Set the dimension of a widget in a particular orientation.- Parameters:
length- Size of the dimension.orientation- HORIZONTAL or VERTICAL
-
setHorizontalMatchStyle
public void setHorizontalMatchStyle(int horizontalMatchStyle, int min, int max, float percent)Set the horizontal style when MATCH_CONSTRAINT is set- Parameters:
horizontalMatchStyle- MATCH_CONSTRAINT_SPREAD or MATCH_CONSTRAINT_WRAPmin- minimum valuemax- maximum valuepercent- Percent width
-
setVerticalMatchStyle
public void setVerticalMatchStyle(int verticalMatchStyle, int min, int max, float percent)Set the vertical style when MATCH_CONSTRAINT is set- Parameters:
verticalMatchStyle- MATCH_CONSTRAINT_SPREAD or MATCH_CONSTRAINT_WRAPmin- minimum valuemax- maximum valuepercent- Percent height
-
setDimensionRatio
public void setDimensionRatio(java.lang.String ratio)
Set the ratio of the widget- Parameters:
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:
ratio- A float value that describes W/H or H/W depending on the provided dimensionRatioSidedimensionRatioSide- The side the ratio should be calculated on, HORIZONTAL, VERTICAL, or UNKNOWN
-
getDimensionRatio
public float getDimensionRatio()
Return the current ratio of this widget- Returns:
- the dimension ratio (HORIZONTAL, VERTICAL, or UNKNOWN)
-
getDimensionRatioSide
public int getDimensionRatioSide()
Return the current side on which ratio will be applied- Returns:
- HORIZONTAL, VERTICAL, or UNKNOWN
-
setHorizontalBiasPercent
public void setHorizontalBiasPercent(float horizontalBiasPercent)
Set the horizontal bias percent to apply when we have two opposite constraints of equal strength- Parameters:
horizontalBiasPercent- the percentage used
-
setVerticalBiasPercent
public void setVerticalBiasPercent(float verticalBiasPercent)
Set the vertical bias percent to apply when we have two opposite constraints of equal strength- Parameters:
verticalBiasPercent- the percentage used
-
setMinWidth
public void setMinWidth(int w)
Set the minimum width of the widget- Parameters:
w- minimum width
-
setMinHeight
public void setMinHeight(int h)
Set the minimum height of the widget- Parameters:
h- minimum height
-
setDimension
public void setDimension(int w, int h)Set both width and height of the widget- Parameters:
w- widthh- height
-
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:
left- left side position of the widgettop- top side position of the widgetright- right side position of the widgetbottom- bottom side position of the widget
-
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:
start- Left/Top side position of the widget.end- Right/Bottom side position of the widget.orientation- Orientation being set (HORIZONTAL/VERTICAL).
-
setHorizontalDimension
public void setHorizontalDimension(int left, int right)Set the positions for the horizontal dimension only- Parameters:
left- left side position of the widgetright- right side position of the widget
-
setVerticalDimension
public void setVerticalDimension(int top, int bottom)Set the positions for the vertical dimension only- Parameters:
top- top side position of the widgetbottom- bottom side position of the widget
-
setBaselineDistance
public void setBaselineDistance(int baseline)
Set the baseline distance relative to the top of the widget- Parameters:
baseline- the distance of the baseline relative to the widget's top
-
setCompanionWidget
public void setCompanionWidget(java.lang.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)
-
getContainerItemSkip
public int getContainerItemSkip()
Accessor for the skip value- Returns:
- skip value
-
setHorizontalWeight
public void setHorizontalWeight(float horizontalWeight)
Set the horizontal weight (only used in chains)- Parameters:
horizontalWeight- Floating point value weight
-
setVerticalWeight
public void setVerticalWeight(float verticalWeight)
Set the vertical weight (only used in chains)- Parameters:
verticalWeight- Floating point value weight
-
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:
horizontalChainStyle- (CHAIN_SPREAD, CHAIN_SPREAD_INSIDE, CHAIN_PACKED)
-
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:
- Horizontal Chain Style
-
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:
verticalChainStyle- (CHAIN_SPREAD, CHAIN_SPREAD_INSIDE, CHAIN_PACKED)
-
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.
-
allowedInBarrier
public boolean allowedInBarrier()
Returns true if this widget should be used in a barrier
-
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:
startType- The type of anchor on this widgettarget- The target widgetendType- The type of anchor on the target widgetmargin- How much margin we want to keep as a minimum distance between the two anchorsgoneMargin- How much margin we want to keep if the target is set toView.GONE
-
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:
from- the anchor we are connecting from (of this widget)to- the anchor we are connecting tomargin- how much margin we want to have
-
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:
constraintFrom- which anchor of this widget to connect fromtarget- the target widgetconstraintTo- the target anchor on the target widget
-
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:
constraintFrom- which anchor of this widget to connect fromtarget- the target widgetconstraintTo- the target anchor on the target widgetmargin- how much margin we want to keep as a minimum distance between the two anchors
-
resetAllConstraints
public void resetAllConstraints()
Reset all the constraints set on this widget
-
resetAnchor
public void resetAnchor(ConstraintAnchor anchor)
Reset the given anchor- Parameters:
anchor- the anchor we want to reset
-
resetAnchors
public void resetAnchors()
Reset all connections
-
getAnchor
public ConstraintAnchor getAnchor(ConstraintAnchor.Type anchorType)
Given a type of anchor, returns the corresponding anchor.- Parameters:
anchorType- type of the anchor (LEFT, TOP, RIGHT, BOTTOM, BASELINE, CENTER_X, CENTER_Y)- Returns:
- the matching anchor
-
getHorizontalDimensionBehaviour
public ConstraintWidget.DimensionBehaviour getHorizontalDimensionBehaviour()
Accessor for the horizontal dimension behaviour- Returns:
- dimension behaviour
-
getVerticalDimensionBehaviour
public ConstraintWidget.DimensionBehaviour getVerticalDimensionBehaviour()
Accessor for the vertical dimension behaviour- Returns:
- dimension behaviour
-
getDimensionBehaviour
public ConstraintWidget.DimensionBehaviour getDimensionBehaviour(int orientation)
Get the widget'sConstraintWidget.DimensionBehaviourin an specific orientation.- Returns:
- The
ConstraintWidget.DimensionBehaviourof the widget.
-
setHorizontalDimensionBehaviour
public void setHorizontalDimensionBehaviour(ConstraintWidget.DimensionBehaviour behaviour)
Set the widget's behaviour for the horizontal dimension- Parameters:
behaviour- the horizontal dimension's behaviour
-
setVerticalDimensionBehaviour
public void setVerticalDimensionBehaviour(ConstraintWidget.DimensionBehaviour behaviour)
Set the widget's behaviour for the vertical dimension- Parameters:
behaviour- the vertical dimension's behaviour
-
isInHorizontalChain
public boolean isInHorizontalChain()
Test if you are in a Horizontal chain- Returns:
- true if in a horizontal chain
-
getPreviousChainMember
public ConstraintWidget getPreviousChainMember(int orientation)
Return the previous chain member if one exists- Parameters:
orientation- HORIZONTAL or VERTICAL- Returns:
- the previous chain member or null if we are the first chain element
-
getNextChainMember
public ConstraintWidget getNextChainMember(int orientation)
Return the next chain member if one exists- Parameters:
orientation- HORIZONTAL or VERTICAL- Returns:
- the next chain member or null if we are the last chain element
-
getHorizontalChainControlWidget
public ConstraintWidget getHorizontalChainControlWidget()
if in a horizontal chain return the left most widget in the chain.- Returns:
- left most widget in chain or null
-
isInVerticalChain
public boolean isInVerticalChain()
Test if you are in a vertical chain- Returns:
- true if in a vertical chain
-
getVerticalChainControlWidget
public ConstraintWidget getVerticalChainControlWidget()
if in a vertical chain return the top most widget in the chain.- Returns:
- top most widget in chain or null
-
addToSolver
public void addToSolver(LinearSystem system, boolean optimize)
Add this widget to the solver- Parameters:
system- the solver we want to add the widget tooptimize- true ifOptimizer.OPTIMIZATION_GRAPHis on
-
setupDimensionRatio
public void setupDimensionRatio(boolean hParentWrapContent, boolean vParentWrapContent, boolean horizontalDimensionFixed, boolean verticalDimensionFixed)Resolves the dimension ratio parameters (mResolvedDimensionRatioSide & mDimensionRatio)- Parameters:
hParentWrapContent- true if parent is in wrap content horizontallyvParentWrapContent- true if parent is in wrap content verticallyhorizontalDimensionFixed- true if this widget horizontal dimension is fixedverticalDimensionFixed- true if this widget vertical dimension is fixed
-
updateFromSolver
public void updateFromSolver(LinearSystem system, boolean optimize)
Update the widget from the values generated by the solver- Parameters:
system- the solver we get the values from.optimize- true ifOptimizer.OPTIMIZATION_GRAPHis on
-
copy
public void copy(ConstraintWidget src, java.util.HashMap<ConstraintWidget,ConstraintWidget> map)
-
updateFromRuns
public void updateFromRuns(boolean updateHorizontal, boolean updateVertical)
-
addChildrenToSolverByDependency
public void addChildrenToSolverByDependency(ConstraintWidgetContainer container, LinearSystem system, java.util.HashSet<ConstraintWidget> widgets, int orientation, boolean addSelf)
-
getSceneString
public void getSceneString(java.lang.StringBuilder ret)
-
-