Barrier
class Barrier : ConstraintHelper
| kotlin.Any | |||
| ↳ | android.view.View | ||
| ↳ | androidx.constraintlayout.widget.ConstraintHelper | ||
| ↳ | androidx.constraintlayout.widget.Barrier |
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 |
|
|---|---|
const Int |
BOTTOM = 3Bottom direction constant |
const Int |
END = 6End Barrier constant |
const Int |
LEFT = 0Left direction constant |
const Int |
RIGHT = 1Right direction constant |
const Int |
START = 5Start direction constant |
const Int |
TOP = 2Top direction constant |
Public constructors |
|---|
Barrier(context: Context!, attrs: AttributeSet!) |
Barrier(context: Context!, attrs: AttributeSet!, defStyleAttr: Int) |
Public functions |
|
|---|---|
Boolean |
This function is deprecated. This method should be called |
Boolean |
Find if this barrier supports gone widgets. |
Int |
Returns the barrier margin |
Int |
getType()Get the barrier type ( |
Unit |
loadParameters(Load the parameters |
Unit |
resolveRtl(widget: ConstraintWidget!, isRtl: Boolean)resolve the RTL |
Unit |
setAllowsGoneWidget(supportGone: Boolean)allows gone widgets to be included in the barrier |
Unit |
setDpMargin(margin: Int)Set a margin on the barrier |
Unit |
Set the barrier margin |
Unit |
Set the barrier type ( |
Protected functions |
|
|---|---|
Unit |
init(attrs: AttributeSet!) |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited properties |
|---|
Constants
Public constructors
Public functions
funallowsGoneWidget(): Boolean
Find if this barrier supports gone widgets.
| Returns | |
|---|---|
Boolean |
true if this barrier supports gone widgets, otherwise false |
getAllowsGoneWidget
fun getAllowsGoneWidget(): Boolean
Find if this barrier supports gone widgets.
| Returns | |
|---|---|
Boolean |
true if this barrier supports gone widgets, otherwise false |
getMargin
fun getMargin(): Int
Returns the barrier margin
| Returns | |
|---|---|
Int |
the barrier margin (in pixels) |
getType
fun getType(): Int
Get the barrier type (Barrier.LEFT, Barrier.TOP, Barrier.RIGHT, Barrier.BOTTOM, Barrier.END, Barrier.START)
loadParameters
fun loadParameters(
constraint: ConstraintSet.Constraint!,
child: HelperWidget!,
layoutParams: ConstraintLayout.LayoutParams!,
mapIdToWidget: SparseArray<ConstraintWidget!>!
): Unit
Load the parameters
| Parameters | |
|---|---|
constraint: ConstraintSet.Constraint! |
|
child: HelperWidget! |
|
layoutParams: ConstraintLayout.LayoutParams! |
|
mapIdToWidget: SparseArray<ConstraintWidget!>! |
resolveRtl
fun resolveRtl(widget: ConstraintWidget!, isRtl: Boolean): Unit
resolve the RTL
| Parameters | |
|---|---|
widget: ConstraintWidget! |
|
isRtl: Boolean |
setAllowsGoneWidget
fun setAllowsGoneWidget(supportGone: Boolean): Unit
allows gone widgets to be included in the barrier
| Parameters | |
|---|---|
supportGone: Boolean |
setDpMargin
fun setDpMargin(margin: Int): Unit
Set a margin on the barrier
| Parameters | |
|---|---|
margin: Int |
in dp |