Utility class representing a Guideline helper object for . Helper objects are not displayed on device (they are marked as ) and are only used for layout purposes. They only work within a .
A Guideline can be either horizontal or vertical:
- Vertical Guidelines have a width of zero and the height of their parent
- Horizontal Guidelines have a height of zero and the width of their parent
Positioning a Guideline is possible in three different ways:
- specifying a fixed distance from the left or the top of a layout ()
- specifying a fixed distance from the right or the bottom of a layout ()
- specifying a percentage of the width or the height of a layout ()
Widgets can then be constrained to a Guideline, allowing multiple widgets to be positioned easily from one Guideline, or allowing reactive layout behavior by using percent positioning.
See the list of attributes in to set a Guideline in XML, as well as the corresponding , and functions in .
Example of a constrained to a vertical :
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.constraint.Guideline android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/guideline" app:layout_constraintGuide_begin="100dp" android:orientation="vertical"/> <Button android:text="Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button" app:layout_constraintLeft_toLeftOf="@+id/guideline" android:layout_marginTop="16dp" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout>
Set the guideline's distance from the top or left edge.
Set a guideline's distance to end.