In this tutorial, we are going to learn Constraint Layout. But To start learning let’s know what is constraint layout and why it introduced.
What is Constraint Layout?
Constraint Layout allows you to create large and complex layouts with a flat view hierarchy (no nested view groups).
Why it is introduced?
We already have Linear layout, Relative layout etc. But When we have to create large layouts then there will be nested view hierarchy which is very complex and hard to read. So, Constraint layout introduced. By using this, We can create complex views with a flat view hierarchy. Also, we can use it by layout editor just by simple drag and drop.
Constraint Layout used Cassowary algorithm. It efficiently solves systems of linear equalities and inequalities. iOS also used same algorithm for auto layout.
How to add dependency of Constraint Layout in project?
- Add maven.google.com repository in project level build.gradle file.
2. Then add dependency in module level build.gradle
3. Sync project with Gradle Files.
Convert an existing layout to Constraint Layout
- Open your layout in Design tab.
- In the Component Tree window, right-click the layout and click Convert layout to Constraint Layout.
Hope this will help you…. We’ll cover up rest of the terms in next parts of constraint layout. Please go through below link: