Constraint Layout — Part I

We learn more by looking for the answer to a question and not finding it than we do from learning the answer itself.
Lloyd Alexander

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?

repositories {

2. Then add dependency in module level build.gradle

dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

3. Sync project with Gradle Files.

Convert an existing 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:

Thank you !!!

As a girl programmer, to keep learning and help ones who needs the skills to be a master, I am available to be a part of an adventurous journey….