Class ConstraintAnchor
- java.lang.Object
-
- androidx.constraintlayout.core.widgets.ConstraintAnchor
-
public class ConstraintAnchor extends java.lang.ObjectModel a constraint relation. Widgets contains anchors, and a constraint relation between two widgets is made by connecting one anchor to another. The anchor will contains a pointer to the target anchor if it is connected.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConstraintAnchor.TypeDefine the type of anchor
-
Field Summary
Fields Modifier and Type Field Description intmMarginConstraintWidgetmOwnerConstraintAnchormTargetConstraintAnchor.TypemType
-
Constructor Summary
Constructors Constructor Description ConstraintAnchor(ConstraintWidget owner, ConstraintAnchor.Type type)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanconnect(ConstraintAnchor toAnchor, int margin)Connects this anchor to another one.booleanconnect(ConstraintAnchor toAnchor, int margin, int goneMargin, boolean forceConnection)Connects this anchor to another one.voidcopyFrom(ConstraintAnchor source, java.util.HashMap<ConstraintWidget,ConstraintWidget> map)voidfindDependents(int orientation, java.util.ArrayList<WidgetGroup> list, WidgetGroup group)java.util.HashSet<ConstraintAnchor>getDependents()intgetFinalValue()intgetMargin()Return the connection's margin from this anchor to its target.ConstraintAnchorgetOpposite()Returns the opposite anchor to this oneConstraintWidgetgetOwner()Return the anchor's ownerSolverVariablegetSolverVariable()Return the solver variable for this anchorConstraintAnchorgetTarget()Return the connection's target (null if not connected)ConstraintAnchor.TypegetType()Return the type of the anchorbooleanhasCenteredDependents()booleanhasDependents()booleanhasFinalValue()booleanisConnected()Returns the connection status of this anchorbooleanisConnectionAllowed(ConstraintWidget target)Return true if we can connect this anchor to this target.booleanisConnectionAllowed(ConstraintWidget target, ConstraintAnchor anchor)Return true if we can connect this anchor to this target.booleanisSideAnchor()Return true if this anchor is a side anchorbooleanisSimilarDimensionConnection(ConstraintAnchor anchor)Return true if the connection to the given anchor is in the same dimension (horizontal or vertical)booleanisValidConnection(ConstraintAnchor anchor)Checks if the connection to a given anchor is valid.booleanisVerticalAnchor()Utility function returning true if this anchor is a vertical one.voidreset()Resets the anchor's connection.voidresetFinalResolution()voidresetSolverVariable(Cache cache)Reset the solver variablevoidsetFinalValue(int finalValue)voidsetGoneMargin(int margin)Set the gone margin of the connection (if there's one)voidsetMargin(int margin)Set the margin of the connection (if there's one)java.lang.StringtoString()Return a string representation of this anchor
-
-
-
Field Detail
-
mOwner
public final ConstraintWidget mOwner
-
mType
public final ConstraintAnchor.Type mType
-
mTarget
public ConstraintAnchor mTarget
-
mMargin
public int mMargin
-
-
Constructor Detail
-
ConstraintAnchor
public ConstraintAnchor(ConstraintWidget owner, ConstraintAnchor.Type type)
Constructor- Parameters:
owner- the widget owner of this anchor.type- the anchor type.
-
-
Method Detail
-
findDependents
public void findDependents(int orientation, java.util.ArrayList<WidgetGroup> list, WidgetGroup group)
-
getDependents
public java.util.HashSet<ConstraintAnchor> getDependents()
-
hasDependents
public boolean hasDependents()
-
hasCenteredDependents
public boolean hasCenteredDependents()
-
setFinalValue
public void setFinalValue(int finalValue)
-
getFinalValue
public int getFinalValue()
-
resetFinalResolution
public void resetFinalResolution()
-
hasFinalValue
public boolean hasFinalValue()
-
copyFrom
public void copyFrom(ConstraintAnchor source, java.util.HashMap<ConstraintWidget,ConstraintWidget> map)
-
getSolverVariable
public SolverVariable getSolverVariable()
Return the solver variable for this anchor
-
resetSolverVariable
public void resetSolverVariable(Cache cache)
Reset the solver variable
-
getOwner
public ConstraintWidget getOwner()
Return the anchor's owner- Returns:
- the Widget owning the anchor
-
getType
public ConstraintAnchor.Type getType()
Return the type of the anchor- Returns:
- type of the anchor.
-
getMargin
public int getMargin()
Return the connection's margin from this anchor to its target.- Returns:
- the margin value. 0 if not connected.
-
getTarget
public ConstraintAnchor getTarget()
Return the connection's target (null if not connected)- Returns:
- the ConstraintAnchor target
-
reset
public void reset()
Resets the anchor's connection.
-
connect
public boolean connect(ConstraintAnchor toAnchor, int margin, int goneMargin, boolean forceConnection)
Connects this anchor to another one.- Returns:
- true if the connection succeeds.
-
connect
public boolean connect(ConstraintAnchor toAnchor, int margin)
Connects this anchor to another one.- Returns:
- true if the connection succeeds.
-
isConnected
public boolean isConnected()
Returns the connection status of this anchor- Returns:
- true if the anchor is connected to another one.
-
isValidConnection
public boolean isValidConnection(ConstraintAnchor anchor)
Checks if the connection to a given anchor is valid.- Parameters:
anchor- the anchor we want to connect to- Returns:
- true if it's a compatible anchor
-
isSideAnchor
public boolean isSideAnchor()
Return true if this anchor is a side anchor- Returns:
- true if side anchor
-
isSimilarDimensionConnection
public boolean isSimilarDimensionConnection(ConstraintAnchor anchor)
Return true if the connection to the given anchor is in the same dimension (horizontal or vertical)- Parameters:
anchor- the anchor we want to connect to- Returns:
- true if it's an anchor on the same dimension
-
setMargin
public void setMargin(int margin)
Set the margin of the connection (if there's one)- Parameters:
margin- the new margin of the connection
-
setGoneMargin
public void setGoneMargin(int margin)
Set the gone margin of the connection (if there's one)- Parameters:
margin- the new margin of the connection
-
isVerticalAnchor
public boolean isVerticalAnchor()
Utility function returning true if this anchor is a vertical one.- Returns:
- true if vertical anchor, false otherwise
-
toString
public java.lang.String toString()
Return a string representation of this anchor- Overrides:
toStringin classjava.lang.Object- Returns:
- string representation of the anchor
-
isConnectionAllowed
public boolean isConnectionAllowed(ConstraintWidget target, ConstraintAnchor anchor)
Return true if we can connect this anchor to this target. We recursively follow connections in order to detect eventual cycles; if we do we disallow the connection. We also only allow connections to direct parent, siblings, and descendants.- Parameters:
target- the ConstraintWidget we are trying to connect toanchor- Allow anchor if it loops back to me directly- Returns:
- if the connection is allowed, false otherwise
-
isConnectionAllowed
public boolean isConnectionAllowed(ConstraintWidget target)
Return true if we can connect this anchor to this target. We recursively follow connections in order to detect eventual cycles; if we do we disallow the connection. We also only allow connections to direct parent, siblings, and descendants.- Parameters:
target- the ConstraintWidget we are trying to connect to- Returns:
- true if the connection is allowed, false otherwise
-
getOpposite
public final ConstraintAnchor getOpposite()
Returns the opposite anchor to this one- Returns:
- opposite anchor
-
-