# Barrier

Summary:[Fields](https://developer.android.com/reference/android/support/constraint/Barrier#lfields)\|[Ctors](https://developer.android.com/reference/android/support/constraint/Barrier#pubctors)\|[Methods](https://developer.android.com/reference/android/support/constraint/Barrier#pubmethods)\|[Protected Methods](https://developer.android.com/reference/android/support/constraint/Barrier#promethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/constraint/Barrier#inhmethods)  

# Barrier

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The Constraint Layout support library has been superseded by the[AndroidX Constraint Layout library](https://developer.android.com/reference/androidx/constraintlayout/classes), which is part of[Jetpack](https://developer.android.com/jetpack). The`Barrier`class has been superseded by[`androidx.constraintlayout.widget.Barrier`](https://developer.android.com/reference/androidx/constraintlayout/widget/Barrier). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX.

`
public


class
Barrier
`  
`


``

extends View


``


`

|---|---|------------------------------------|
| java.lang.Object                         |||
| ↳ | View                                  ||
|   | ↳ | android.support.constraint.Barrier |

<br />

*** ** * ** ***

**Added in 1.1**

A Barrier references multiple widgets as input, and creates a virtual guideline based on the most extreme widget on the specified side. For example, a left barrier will align to the left of all the referenced views.

<br />

## Example

<br />

![](https://developer.android.com/static/reference/android/support/constraint/resources/images/barrier-buttons.png)
Let's have two buttons, @id/button1 and @id/button2. The constraint_referenced_ids field will reference them by simply having them as comma-separated list:  

         <android.support.constraint.Barrier
                  android:id="@+id/barrier"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  app:barrierDirection="start"
                  app:constraint_referenced_ids="button1,button2" />
         
         
With the barrier direction set to start, we will have the following result:

<br />

![](https://developer.android.com/static/reference/android/support/constraint/resources/images/barrier-start.png)

Reversely, with the direction set to end, we will have:

<br />

![](https://developer.android.com/static/reference/android/support/constraint/resources/images/barrier-end.png)

If the widgets dimensions change, the barrier will automatically move according to its direction to get the most extreme widget:

<br />

![](https://developer.android.com/static/reference/android/support/constraint/resources/images/barrier-adapt.png)

Other widgets can then be constrained to the barrier itself, instead of the individual widget. This allows a layout to automatically adapt on widget dimension changes (e.g. different languages will end up with different length for similar worlds).

## GONE widgets handling

If the barrier references GONE widgets, the default behavior is to create a barrier on the resolved position of the GONE widget. If you do not want to have the barrier take GONE widgets into account, you can change this by setting the attribute*barrierAllowsGoneWidgets*to false (default being true).

<br />

<br />

<br />

## Summary

|                                                                    ### Fields                                                                     ||
|----------------------------|-----------------------------------------------------------------------------------------------------------------------|
| ` public static final int` | [BOTTOM](https://developer.android.com/reference/android/support/constraint/Barrier#BOTTOM) Bottom direction constant |
| ` public static final int` | [END](https://developer.android.com/reference/android/support/constraint/Barrier#END) End Barrier constant            |
| ` public static final int` | [LEFT](https://developer.android.com/reference/android/support/constraint/Barrier#LEFT) Left direction constant       |
| ` public static final int` | [RIGHT](https://developer.android.com/reference/android/support/constraint/Barrier#RIGHT) Right direction constant    |
| ` public static final int` | [START](https://developer.android.com/reference/android/support/constraint/Barrier#START) Start direction constant    |
| ` public static final int` | [TOP](https://developer.android.com/reference/android/support/constraint/Barrier#TOP) Top direction constant          |

|                                                                                    ### Public constructors                                                                                    ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[Barrier](https://developer.android.com/reference/android/support/constraint/Barrier#Barrier(Context))`(Context context) `                                                              |
| ` `[Barrier](https://developer.android.com/reference/android/support/constraint/Barrier#Barrier(Context,%20AttributeSet))`(Context context, AttributeSet attrs) `                          |
| ` `[Barrier](https://developer.android.com/reference/android/support/constraint/Barrier#Barrier(Context,%20AttributeSet,%20int))`(Context context, AttributeSet attrs, int defStyleAttr) ` |

|                                                                                                                                                                                                                                                                                         ### Public methods                                                                                                                                                                                                                                                                                         ||
|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` boolean` | ` `[allowsGoneWidget](https://developer.android.com/reference/android/support/constraint/Barrier#allowsGoneWidget())`() `                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ` int`     | ` `[getMargin](https://developer.android.com/reference/android/support/constraint/Barrier#getMargin())`() ` Returns the barrier margin                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ` int[]`   | ` `[getReferencedIds](https://developer.android.com/reference/android/support/constraint/Barrier#getReferencedIds())`() ` Helpers typically reference a collection of ids                                                                                                                                                                                                                                                                                                                                                                                                              |
| ` int`     | ` `[getType](https://developer.android.com/reference/android/support/constraint/Barrier#getType())`() ` Get the barrier type (`Barrier.LEFT`,`Barrier.TOP`,`Barrier.RIGHT`,`Barrier.BOTTOM`,`Barrier.END`,`Barrier.START`)                                                                                                                                                                                                                                                                                                                                                             |
| ` void`    | ` `[loadParameters](https://developer.android.com/reference/android/support/constraint/Barrier#loadParameters(android.support.constraint.ConstraintSet.Constraint,%20HelperWidget,%20android.support.constraint.ConstraintLayout.LayoutParams,%20<any>))`(`[ConstraintSet.Constraint](https://developer.android.com/reference/android/support/constraint/ConstraintSet.Constraint)` constraint, HelperWidget child, `[ConstraintLayout.LayoutParams](https://developer.android.com/reference/android/support/constraint/ConstraintLayout.LayoutParams)` layoutParams, ` mapIdToWidget) |
| ` void`    | ` `[resolveRtl](https://developer.android.com/reference/android/support/constraint/Barrier#resolveRtl(ConstraintWidget,%20boolean))`(ConstraintWidget widget, boolean isRtl) `                                                                                                                                                                                                                                                                                                                                                                                                         |
| ` void`    | ` `[setAllowsGoneWidget](https://developer.android.com/reference/android/support/constraint/Barrier#setAllowsGoneWidget(boolean))`(boolean supportGone) `                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ` void`    | ` `[setDpMargin](https://developer.android.com/reference/android/support/constraint/Barrier#setDpMargin(int))`(int margin) ` Set a margin on the barrier                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` void`    | ` `[setMargin](https://developer.android.com/reference/android/support/constraint/Barrier#setMargin(int))`(int margin) ` Set the barrier margin                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` void`    | ` `[setReferencedIds](https://developer.android.com/reference/android/support/constraint/Barrier#setReferencedIds(int[]))`(int[] ids) ` Helpers typically reference a collection of ids                                                                                                                                                                                                                                                                                                                                                                                                |
| ` void`    | ` `[setType](https://developer.android.com/reference/android/support/constraint/Barrier#setType(int))`(int type) ` Set the barrier type (`Barrier.LEFT`,`Barrier.TOP`,`Barrier.RIGHT`,`Barrier.BOTTOM`,`Barrier.END`,`Barrier.START`)                                                                                                                                                                                                                                                                                                                                                  |
| ` void`    | ` `[updatePostConstraints](https://developer.android.com/reference/android/support/constraint/Barrier#updatePostConstraints(android.support.constraint.ConstraintLayout))`(`[ConstraintLayout](https://developer.android.com/reference/android/support/constraint/ConstraintLayout)` constainer) `                                                                                                                                                                                                                                                                                     |
| ` void`    | ` `[updatePreLayout](https://developer.android.com/reference/android/support/constraint/Barrier#updatePreLayout(ConstraintWidgetContainer,%20Helper,%20<any>))`(ConstraintWidgetContainer container, Helper helper, ` map)                                                                                                                                                                                                                                                                                                                                                             |

|                                                                                                                              ### Protected methods                                                                                                                              ||
|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` View[]` | ` `[getViews](https://developer.android.com/reference/android/support/constraint/Barrier#getViews(android.support.constraint.ConstraintLayout))`(`[ConstraintLayout](https://developer.android.com/reference/android/support/constraint/ConstraintLayout)` layout) ` |

| ### Inherited methods |
|-----------------------|---|
| From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Fields

### BOTTOM

```
public static final int BOTTOM
```

Bottom direction constant

<br />

### END

```
public static final int END
```

End Barrier constant

<br />

### LEFT

```
public static final int LEFT
```

Left direction constant

<br />

### RIGHT

```
public static final int RIGHT
```

Right direction constant

<br />

### START

```
public static final int START
```

Start direction constant

<br />

### TOP

```
public static final int TOP
```

Top direction constant

<br />

## Public constructors

### Barrier

```
public Barrier (Context context)
```

<br />

<br />

|         Parameters          ||
|-----------|------------------|
| `context` | `Context` <br /> |

### Barrier

```
public Barrier (Context context, 
                AttributeSet attrs)
```

<br />

<br />

|            Parameters            ||
|-----------|-----------------------|
| `context` | `Context` <br />      |
| `attrs`   | `AttributeSet` <br /> |

### Barrier

```
public Barrier (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)
```

<br />

<br />

|              Parameters               ||
|----------------|-----------------------|
| `context`      | `Context` <br />      |
| `attrs`        | `AttributeSet` <br /> |
| `defStyleAttr` | `int` <br />          |

## Public methods

### allowsGoneWidget

```
public boolean allowsGoneWidget ()
```

<br />

<br />

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### getMargin

```
public int getMargin ()
```

Returns the barrier margin

<br />

|                   Returns                    ||
|-------|---------------------------------------|
| `int` | the barrier margin (in pixels) <br /> |

### getReferencedIds

```
public int[] getReferencedIds ()
```

Helpers typically reference a collection of ids

<br />

|            Returns             ||
|---------|-----------------------|
| `int[]` | ids referenced <br /> |

### getType

```
public int getType ()
```

Get the barrier type (`Barrier.LEFT`,`Barrier.TOP`,`Barrier.RIGHT`,`Barrier.BOTTOM`,`Barrier.END`,`Barrier.START`)

<br />

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### loadParameters

```
public void loadParameters (ConstraintSet.Constraint constraint, 
                HelperWidget child,
                ConstraintLayout.LayoutParams layoutParams,
                 mapIdToWidget)
```

<br />

<br />

|                       Parameters                        ||
|-----------------|----------------------------------------|
| `constraint`    | `ConstraintSet.Constraint` <br />      |
| `child`         | `HelperWidget` <br />                  |
| `layoutParams`  | `ConstraintLayout.LayoutParams` <br /> |
| `mapIdToWidget` | <br />                                 |

### resolveRtl

```
public void resolveRtl (ConstraintWidget widget, 
                boolean isRtl)
```

<br />

<br />

|             Parameters              ||
|----------|---------------------------|
| `widget` | `ConstraintWidget` <br /> |
| `isRtl`  | `boolean` <br />          |

### setAllowsGoneWidget

```
public void setAllowsGoneWidget (boolean supportGone)
```

<br />

<br />

|           Parameters            ||
|---------------|------------------|
| `supportGone` | `boolean` <br /> |

### setDpMargin

```
public void setDpMargin (int margin)
```

Set a margin on the barrier

<br />

|          Parameters           ||
|----------|---------------------|
| `margin` | `int`: in dp <br /> |

### setMargin

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

Set the barrier margin

<br />

|            Parameters             ||
|----------|-------------------------|
| `margin` | `int`: in pixels <br /> |

### setReferencedIds

```
public void setReferencedIds (int[] ids)
```

Helpers typically reference a collection of ids

<br />

|     Parameters      ||
|-------|--------------|
| `ids` | `int` <br /> |

|            Returns            ||
|--------|-----------------------|
| `void` | ids referenced <br /> |

### setType

```
public void setType (int type)
```

Set the barrier type (`Barrier.LEFT`,`Barrier.TOP`,`Barrier.RIGHT`,`Barrier.BOTTOM`,`Barrier.END`,`Barrier.START`)

<br />

|      Parameters      ||
|--------|--------------|
| `type` | `int` <br /> |

### updatePostConstraints

```
public void updatePostConstraints (ConstraintLayout constainer)
```

<br />

<br />

|               Parameters                ||
|--------------|---------------------------|
| `constainer` | `ConstraintLayout` <br /> |

### updatePreLayout

```
public void updatePreLayout (ConstraintWidgetContainer container,
                Helper helper,
                 map)
```

<br />

<br />

|                   Parameters                    ||
|-------------|------------------------------------|
| `container` | `ConstraintWidgetContainer` <br /> |
| `helper`    | `Helper` <br />                    |
| `map`       | <br />                             |

## Protected methods

### getViews

```
protected View[] getViews (ConstraintLayout layout)
```

<br />

<br />

|             Parameters              ||
|----------|---------------------------|
| `layout` | `ConstraintLayout` <br /> |

|     Returns      ||
|----------|--------|
| `View[]` | <br /> |