
Other views can then constrain themselves to the barrier.īelow is an example of creating a barrier from two views and constraining a view to it. Barriers can be vertical or horizontal and can be created to the top, bottom, left or right of the referenced views. If one of the views grows, the barrier will adjust its size to the largest height or width of the referenced items. A barrier is an invisible view that contains reference to the views that you wish to use to form a “barrier” against. Barriersīarriers are one of my favourite features in ConstraintLayout.


Other views in the layout can then constrain themselves to the guideline. If you are curious as to how a guideline looks in XML, this is what it looks like: To create a guideline and use it, see below: Guidelines in ConstraintLayout To cycle through the different guideline modes, you can click the round icon at the top of the guideline. Guidelines can be specified in dp from start or end of the screen or they can be a percentage of the width of the screen. Views can be aligned to a guideline which can simplify layouts, especially if you have the same margin values duplicated on a lot of elements. Guidelines are small visual helpers to design layouts with.

In order to use the beta version of ConstraintLayout, make sure you have at least the following dependency in your app level adle file: implementation ':constraint-layout:1.1.0-beta1' Guidelines Some of these features require using Android Studio 3.0 Beta 5 and the beta version of ConstraintLayout. This blog post aims to cover some of the new features, namely Guidelines, Barriers, Chains and Groups. Since my initial blog post about ConstraintLayout, there have been a whole bunch of new features added (and lots of improvements) to ConstraintLayout.
