Guidelines in Constraint Layout are invisible lines which are not visible to user but help developers to design the layout easily and constrain views to these guidelines, so that design can be more clear and interactive. But guidelines only work in Constraint Layout as guidelines require something to be constrained to them.
There are two types of guidelines:
- Horizontal Guidelines: These guidelines have a height of zero and its width is equal to its parent Constraint Layout.
- Vertical Guidelines: These guidelines have a width of zero and its height is equal to its parent Constraint Layout.
Now we can position guidelines in three different ways:
- By using (layout_constraintGuide_begin) to specify a fixed distance from the left or the top of a layout.
- By using (layout_constraintGuide_end) to specify a fixed distance from the right or the bottom of a layout.
- By using (layout_constraint_percent) to specify percentage of the width or the height of a layout.
Note: Guidelines can only be used with Constraint layout. To know about constraint layout you can refer Constraint layout.
The following steps can be used to make use of guidelines:
Step 1: Use constraint layout in your application.
Step 2: Click on the icon shown below or you can also search horizonal or vertical guidelines in palette.
Step 3: Select guidelines which you want to use (horizontal or vertical).
Step 4: Use following code to use attributes to position guidelines in end, begin and decide percentage of width or height of layout.
Hence, guidelines can be used as taught above and can help Android developers to design interactive layouts.