public class Barrier extends ConstraintHelper


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.

Example

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:
        <androidx.constraintlayout.widget.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:

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

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

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

Summary

Constants

static final int
BOTTOM = 3

Bottom direction constant

static final int
END = 6

End Barrier constant

static final int
LEFT = 0

Left direction constant

static final int
RIGHT = 1

Right direction constant

static final int
START = 5

Start direction constant

static final int
TOP = 2

Top direction constant

Public constructors

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

Public methods

boolean

This method is deprecated.

This method should be called getAllowsGoneWidget such that allowsGoneWidget can be accessed as a property from Kotlin; {@see https://android.github.io/kotlin-guides/interop.html#property-prefixes}.

boolean

Find if this barrier supports gone widgets.

int

Returns the barrier margin

int

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

void
loadParameters(
    ConstraintSet.Constraint constraint,
    HelperWidget child,
    ConstraintLayout.LayoutParams layoutParams,
    SparseArray<ConstraintWidget> mapIdToWidget
)

Load the parameters

void
resolveRtl(ConstraintWidget widget, boolean isRtl)

resolve the RTL

void
setAllowsGoneWidget(boolean supportGone)

allows gone widgets to be included in the barrier

void
setDpMargin(int margin)

Set a margin on the barrier

void
setMargin(int margin)

Set the barrier margin

void
setType(int type)

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

Protected methods

void

Inherited Constants

From androidx.constraintlayout.widget.ConstraintHelper
static final String
CHILD_TAG = "CONSTRAINT_LAYOUT_HELPER_CHILD"
From android.view.View
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final int
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = "creditCardExpirationDate"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = "creditCardExpirationMonth"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = "creditCardExpirationYear"
static final String
static final String
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int
GONE = 8
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
KEEP_SCREEN_ON = 67108864
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
NO_ID = -1
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final String
VIEW_LOG_TAG = "View"
static final int
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>

Inherited methods

From androidx.constraintlayout.widget.ConstraintHelper
void
addView(View view)

Add a view to the helper.

void

hook for helpers to apply parameters in MotionLayout

void
void
void
boolean
containsId(int id)

does id table contain the id

int[]

Helpers typically reference a collection of ids

View[]
int
indexFromId(int id)

find the position of an id

static boolean
void
void
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
int

Remove a given view from the helper.

void
setIds(String idList)
void
void
setReferencedIds(int[] ids)

Helpers typically reference a collection of ids

void
setTag(int key, Object tag)
void

update after constraints are resolved

void

Allows a helper a chance to update its internal object post layout or set up connections for the pointed elements

void
void

called before the draw

void

Allows a helper a chance to update its internal object pre layout or set up connections for the pointed elements

void
updatePreLayout(
    ConstraintWidgetContainer container,
    Helper helper,
    SparseArray<ConstraintWidget> map
)

called before solver resolution

void

Allows a helper to replace the default ConstraintWidget in LayoutParams by its own subclass

From android.view.View
void
void
addExtraDataToAccessibilityNodeInfo(
    AccessibilityNodeInfo info,
    String extraDataKey,
    Bundle arguments
)
void
addFocusables(ArrayList<View> views, int direction)
void
void
void
void
void
ViewPropertyAnimator
void
void
boolean
void
void

This method is deprecated.

void
boolean
boolean
boolean
boolean
boolean
canScrollHorizontally(int direction)
boolean
canScrollVertically(int direction)
final void
void
final void
boolean
void
void
void
static int
combineMeasuredStates(int curState, int newState)
int
int
int
void
WindowInsets
int
int
int
AccessibilityNodeInfo
void
void

This method is deprecated.

WindowInsets
boolean
void
void
dispatchCreateViewTranslationRequest(
    Map<AutofillId, long[]> viewIds,
    int[] supportedFormats,
    TranslationCapability capability,
    List<ViewTranslationRequest> requests
)
void
boolean
void
void
dispatchDrawableHotspotChanged(float x, float y)
void
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
boolean
dispatchNestedPreFling(float velocityX, float velocityY)
boolean
dispatchNestedPrePerformAccessibilityAction(
    int action,
    Bundle arguments
)
boolean
dispatchNestedPreScroll(
    int dx,
    int dy,
    int[] consumed,
    int[] offsetInWindow
)
boolean
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int[] offsetInWindow
)
void
dispatchPointerCaptureChanged(boolean hasCapture)
boolean
void
void
void
void
void
dispatchScrollCaptureSearch(
    Rect localVisibleRect,
    Point windowOffset,
    Consumer<ScrollCaptureTarget> targets
)
void
dispatchSetActivated(boolean activated)
void
dispatchSetPressed(boolean pressed)
void
dispatchSetSelected(boolean selected)
void
void

This method is deprecated.

boolean
boolean
boolean
dispatchUnhandledMove(View focused, int direction)
void
dispatchVisibilityChanged(View changedView, int visibility)
void
dispatchWindowFocusChanged(boolean hasFocus)
void
void
WindowInsets
WindowInsetsAnimation.Bounds
void

This method is deprecated.

void
void
draw(Canvas canvas)
void
drawableHotspotChanged(float x, float y)
void
View
final OnBackInvokedDispatcher
final T
<T extends View> findViewById(int id)
final T
<T extends View> findViewWithTag(Object tag)
void
findViewsWithText(
    ArrayList<View> outViews,
    CharSequence searched,
    int flags
)
boolean

This method is deprecated.

View
focusSearch(int direction)
void
forceHasOverlappingRendering(boolean hasOverlappingRendering)
void
boolean
void
generateDisplayHash(
    String hashAlgorithm,
    Rect bounds,
    Executor executor,
    DisplayHashResultCallback callback
)
static int
CharSequence
View.AccessibilityDelegate
int
AccessibilityNodeProvider
CharSequence
int
int
String
String
float
Animation
Matrix
IBinder
int[]
Map<IntegerInteger>
String[]
final AutofillId
int
AutofillValue
Drawable
BlendMode
ColorStateList
PorterDuff.Mode
int
final int
float
int
float
Rect
boolean
final boolean
final ContentCaptureSession
CharSequence
final Context
ContextMenu.ContextMenuInfo
final boolean
static int
getDefaultSize(int size, int measureSpec)
Display
final int[]
Bitmap

This method is deprecated.

int

This method is deprecated.

int

This method is deprecated.

void
long
float
int
boolean
boolean
int
ArrayList<View>
getFocusables(int direction)
void
Drawable
int
BlendMode
ColorStateList
PorterDuff.Mode