Guidelines in Android ConstraintLayout

13 Sep, 2021
Guidelines in Constraint Layout are invisible lines that are not visible to users 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.
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.
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.
Horizontal and vertical guidelines
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.
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. 
Step 1: Use constraint layout in your application.
Step 2: Click on the icon shown below or you can also search horizontal 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.
XML
<androidx.constraintlayout.widget.Guideline  android:id="@+id/guideline7"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:orientation="vertical"  app:layout_constraintGuide_begin="20dp" />  <androidx.constraintlayout.widget.Guideline  android:id="@+id/guideline8"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:orientation="vertical"  app:layout_constraintGuide_end="20dp" />  <androidx.constraintlayout.widget.Guideline  android:id="@+id/guideline5"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:orientation="horizontal"  app:layout_constraintGuide_begin="20dp" />  <androidx.constraintlayout.widget.Guideline  android:id="@+id/guideline6"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:orientation="horizontal"  app:layout_constraintGuide_end="20dp" />  <androidx.constraintlayout.widget.Guideline  android:id="@+id/guideline9"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:orientation="horizontal"  app:layout_constraintGuide_begin="20dp"  app:layout_constraintGuide_percent="0.75" />
Hence, guidelines can be used as taught above and can help Android developers to design interactive layouts.
sagar0719kumar
Android
Android
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Add Views Dynamically and Store Data in Arraylist in Android?
Android SDK and it's Components
How to Communicate Between Fragments in Android?
Flutter - Custom Bottom Navigation Bar
Retrofit with Kotlin Coroutine in Android
How to Post Data to API using Retrofit in Android?
Flutter - Stack Widget
Activity Lifecycle in Android with Demo App
Introduction to Android Development
Data Binding in Android with Example