# ConstraintAnchor

Artifact: [androidx.constraintlayout:constraintlayout-core](https://developer.android.com/jetpack/androidx/releases/constraintlayout) [View Source](https://cs.android.com/search?q=file:androidx/constraintlayout/core/widgets/ConstraintAnchor.java+class:androidx.constraintlayout.core.widgets.ConstraintAnchor) Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

*** ** * ** ***


```
public class ConstraintAnchor
```

<br />

*** ** * ** ***

Model 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.

## Summary

| ### Nested types |
|---|
| `public enum https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor.Type` Define the type of anchor |

| ### Public fields |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#mMargin()` |
| `final https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintWidget` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#mOwner()` |
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#mTarget()` |
| `final https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor.Type` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#mType()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#ConstraintAnchor(androidx.constraintlayout.core.widgets.ConstraintWidget,androidx.constraintlayout.core.widgets.ConstraintAnchor.Type)(https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintWidget owner, https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor.Type type)` Constructor |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#connect(androidx.constraintlayout.core.widgets.ConstraintAnchor,int)(https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor toAnchor, int margin)` Connects this anchor to another one. |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#connect(androidx.constraintlayout.core.widgets.ConstraintAnchor,int,int,boolean)( https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor toAnchor, int margin, int goneMargin, boolean forceConnection )` Connects this anchor to another one. |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#copyFrom(androidx.constraintlayout.core.widgets.ConstraintAnchor,java.util.HashMap<androidx.constraintlayout.core.widgets.ConstraintWidget,androidx.constraintlayout.core.widgets.ConstraintWidget>)( https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor source, https://developer.android.com/reference/java/util/HashMap.html<https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintWidget, https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintWidget> map )` |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#findDependents(int,java.util.ArrayList<androidx.constraintlayout.core.widgets.analyzer.WidgetGroup>,androidx.constraintlayout.core.widgets.analyzer.WidgetGroup)( int orientation, https://developer.android.com/reference/java/util/ArrayList.html<https://developer.android.com/reference/androidx/constraintlayout/core/widgets/analyzer/WidgetGroup> list, https://developer.android.com/reference/androidx/constraintlayout/core/widgets/analyzer/WidgetGroup group )` |
| `https://developer.android.com/reference/java/util/HashSet.html<https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor>` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#getDependents()()` |
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#getFinalValue()()` |
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#getMargin()()` Return the connection's margin from this anchor to its target. |
| `final https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#getOpposite()()` Returns the opposite anchor to this one |
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintWidget` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#getOwner()()` Return the anchor's owner |
| `https://developer.android.com/reference/androidx/constraintlayout/core/SolverVariable` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#getSolverVariable()()` Return the solver variable for this anchor |
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#getTarget()()` Return the connection's target (null if not connected) |
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor.Type` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#getType()()` Return the type of the anchor |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#hasCenteredDependents()()` |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#hasDependents()()` |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#hasFinalValue()()` |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#isConnected()()` Returns the connection status of this anchor |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#isConnectionAllowed(androidx.constraintlayout.core.widgets.ConstraintWidget)(https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintWidget target)` Return true if we can connect this anchor to this target. |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#isConnectionAllowed(androidx.constraintlayout.core.widgets.ConstraintWidget,androidx.constraintlayout.core.widgets.ConstraintAnchor)(https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintWidget target, https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor anchor)` Return true if we can connect this anchor to this target. |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#isSideAnchor()()` Return true if this anchor is a side anchor |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#isSimilarDimensionConnection(androidx.constraintlayout.core.widgets.ConstraintAnchor)(https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor anchor)` Return true if the connection to the given anchor is in the same dimension (horizontal or vertical) |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#isValidConnection(androidx.constraintlayout.core.widgets.ConstraintAnchor)(https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor anchor)` Checks if the connection to a given anchor is valid. |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#isVerticalAnchor()()` Utility function returning true if this anchor is a vertical one. |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#reset()()` Resets the anchor's connection. |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#resetFinalResolution()()` |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#resetSolverVariable(androidx.constraintlayout.core.Cache)(https://developer.android.com/reference/androidx/constraintlayout/core/Cache cache)` Reset the solver variable |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#setFinalValue(int)(int finalValue)` |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#setGoneMargin(int)(int margin)` Set the gone margin of the connection (if there's one) |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#setMargin(int)(int margin)` Set the margin of the connection (if there's one) |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor#toString()()` Return a string representation of this anchor |

## Public fields

### mMargin

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public int mMargin
```

### mOwner

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public final ConstraintWidget mOwner
```

### mTarget

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public ConstraintAnchor mTarget
```

### mType

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public final ConstraintAnchor.Type mType
```

## Public constructors

### ConstraintAnchor

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public ConstraintAnchor(ConstraintWidget owner, ConstraintAnchor.Type type)
```

Constructor

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintWidget owner` | the widget owner of this anchor. |
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor.Type type` | the anchor type. |

## Public methods

### connect

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public boolean connect(ConstraintAnchor toAnchor, int margin)
```

Connects this anchor to another one.

| Returns |
|---|---|
| `boolean` | true if the connection succeeds. |

### connect

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public boolean connect(
    ConstraintAnchor toAnchor,
    int margin,
    int goneMargin,
    boolean forceConnection
)
```

Connects this anchor to another one.

| Returns |
|---|---|
| `boolean` | true if the connection succeeds. |

### copyFrom

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public void copyFrom(
    ConstraintAnchor source,
    HashMap<ConstraintWidget, ConstraintWidget> map
)
```

### findDependents

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public void findDependents(
    int orientation,
    ArrayList<WidgetGroup> list,
    WidgetGroup group
)
```

### getDependents

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public HashSet<ConstraintAnchor> getDependents()
```

### getFinalValue

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public int getFinalValue()
```

### getMargin

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public int getMargin()
```

Return the connection's margin from this anchor to its target.

| Returns |
|---|---|
| `int` | the margin value. 0 if not connected. |

### getOpposite

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public final ConstraintAnchor getOpposite()
```

Returns the opposite anchor to this one

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor` | opposite anchor |

### getOwner

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public ConstraintWidget getOwner()
```

Return the anchor's owner

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintWidget` | the Widget owning the anchor |

### getSolverVariable

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public SolverVariable getSolverVariable()
```

Return the solver variable for this anchor

### getTarget

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public ConstraintAnchor getTarget()
```

Return the connection's target (null if not connected)

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor` | the ConstraintAnchor target |

### getType

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public ConstraintAnchor.Type getType()
```

Return the type of the anchor

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor.Type` | type of the anchor. |

### hasCenteredDependents

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public boolean hasCenteredDependents()
```

### hasDependents

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public boolean hasDependents()
```

### hasFinalValue

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public boolean hasFinalValue()
```

### isConnected

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public boolean isConnected()
```

Returns the connection status of this anchor

| Returns |
|---|---|
| `boolean` | true if the anchor is connected to another one. |

### isConnectionAllowed

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
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 |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintWidget target` | the ConstraintWidget we are trying to connect to |

| Returns |
|---|---|
| `boolean` | true if the connection is allowed, false otherwise |

### isConnectionAllowed

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
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 |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintWidget target` | the ConstraintWidget we are trying to connect to |
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor anchor` | Allow anchor if it loops back to me directly |

| Returns |
|---|---|
| `boolean` | if the connection is allowed, false otherwise |

### isSideAnchor

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public boolean isSideAnchor()
```

Return true if this anchor is a side anchor

| Returns |
|---|---|
| `boolean` | true if side anchor |

### isSimilarDimensionConnection

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public boolean isSimilarDimensionConnection(ConstraintAnchor anchor)
```

Return true if the connection to the given anchor is in the same dimension (horizontal or vertical)

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor anchor` | the anchor we want to connect to |

| Returns |
|---|---|
| `boolean` | true if it's an anchor on the same dimension |

### isValidConnection

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public boolean isValidConnection(ConstraintAnchor anchor)
```

Checks if the connection to a given anchor is valid.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/widgets/ConstraintAnchor anchor` | the anchor we want to connect to |

| Returns |
|---|---|
| `boolean` | true if it's a compatible anchor |

### isVerticalAnchor

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public boolean isVerticalAnchor()
```

Utility function returning true if this anchor is a vertical one.

| Returns |
|---|---|
| `boolean` | true if vertical anchor, false otherwise |

### reset

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public void reset()
```

Resets the anchor's connection.

### resetFinalResolution

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public void resetFinalResolution()
```

### resetSolverVariable

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public void resetSolverVariable(Cache cache)
```

Reset the solver variable

### setFinalValue

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public void setFinalValue(int finalValue)
```

### setGoneMargin

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public void setGoneMargin(int margin)
```

Set the gone margin of the connection (if there's one)

| Parameters |
|---|---|
| `int margin` | the new margin of the connection |

### setMargin

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public void setMargin(int margin)
```

Set the margin of the connection (if there's one)

| Parameters |
|---|---|
| `int margin` | the new margin of the connection |

### toString

```
public String toString()
```

Return a string representation of this anchor

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | string representation of the anchor |