A Constraint Layout is a ViewGroup layout on Android that gives you adaptable and flexible ways to create views for your apps. It is an advanced version of a Relative layout. This layout is used to reduce the child view hierarchies and improve performance.
A Constraint Layout is an android.view.ViewGroup which allows you to position and size widgets in a flexible way.
It is also the default layout in Android Studio, and gives you many ways to place objects. You can constrain the objects to their container, to each other, or to guidelines. This allows you to create large, complex layouts, dynamic and responsive views in a flat hierarchy. It even supports animations!
- Wrap Content –It wraps the view size according to data
- Any Size – This is very similar to match parent.
- Fixed Size – This allows standard height and width (fixed sizes)
Advantages of Constraint Layout over Other Layouts
- One great advantage of the constraint layout is that you can perform animations on your layout views with very little code.
- You can build your complete layout with simple drag-and-drop on the Android Studio design editor.
- You can control what happens to a group of widgets through a single line of code.
- This ViewGroup improve performance over other layouts.
Note: Constraint Layout is available as a support library that can be used on Android systems starting with API level 9 (Gingerbread).