In this post, you will learn how to create responsive user interface in android studio. Responsive user interface means that your user interface design will be supportable on all different screen sizes and screen densities. we will also cover on different design for phone and tablets and we will learn how to use advanced layout for handling complexing designs called as constraint layout. Constraint layout is best way to create responsive layout. With constraint you can not create pixel perfect design but it is very closed to pixel perfect design.
Short Introduction of constraint layout
It is similar to relative layout with set of constraint (Positioning constraint). It allow you to position UI elements with constraints to other UI elements. It provide a flat view hierarchy (no more nested views). With the help of constraint layout, you can set same size of UI element for different screen sizes except font size ( unit of font size is sp ).
Learning objectives of constraint layout
In a constraint layout, you must set at least two positions, that is one from vertical position (top or bottom of element) and other is horizontal (left or right of element), otherwise it will show you error in the layout section.
Practical Example
In the above example, there are 4 button align in special order. The above button have 16dp margin from top and 8dp margin from left and right, while two buttons in middle is centered vertically and horizontal chain is applied to make button adjust horizontal with each other.
In the above image, you will see different features, it is very important to understand each feature in order to create complex design easily through constraint layout. The first option is about constraint and in the constraint
![]() |
how to create responsive UI in android |
Short Introduction of constraint layout
It is similar to relative layout with set of constraint (Positioning constraint). It allow you to position UI elements with constraints to other UI elements. It provide a flat view hierarchy (no more nested views). With the help of constraint layout, you can set same size of UI element for different screen sizes except font size ( unit of font size is sp ).
Learning objectives of constraint layout
- How to use chains to position multiple elements
- How to use barriers for aligning elements in different element sizes or screen sizes
- How to add constraints to elements for positioning and aligning with other elements
- Adjusting an elements's layout dimensions and margin
- How to use guidelines for division of android screen in percentage
- How to do scaling of element size with android screen size.
In a constraint layout, you must set at least two positions, that is one from vertical position (top or bottom of element) and other is horizontal (left or right of element), otherwise it will show you error in the layout section.
Practical Example
![]() |
Constraint Layout in Android studio |
In the above example, there are 4 button align in special order. The above button have 16dp margin from top and 8dp margin from left and right, while two buttons in middle is centered vertically and horizontal chain is applied to make button adjust horizontal with each other.
![]() |
features of constraint layout |
![]() |
constraints in constraint layout |
There are 5 things in constraints, number one is
fixed, number two is
wrap content, number three is
Match constraint, number four is size ratio and number five is constraint bias.



![]() |
constraints example 1 |