You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
John Hoford edited this page Jan 27, 2023
·
2 revisions
Barrier
public class Barrier
extends View
java.lang.Object`
↳ android.view.View`
↳ 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:
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).