Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constraint layout vs Relative layout

I have been mostly designing my views using Relative layout as it works great when you put things positioned from the right edge, center or simply relative to each other. That would great on different screen sizes so the views are more spread.

With the introduction of constraint layout, I find it that it is more powerfull and it achives the same purposes while giving more flexibility.

Does that mean that Relative layout is no longer needed and can be replaced with Constraint all the time? Is there a situation where you shouldn't go constraint view and go for relative layout instead?

Thank you

like image 794
Snake Avatar asked May 14 '17 20:05

Snake


People also ask

What is difference between constraint and relative layout?

Unlike RelativeLayout , ConstraintLayout offers a bias value that is used to position a view in terms of 0% and 100% horizontal and vertical offset relative to the handles (marked with a red circle). These percentages (and fractions) offer seamless positioning of the view across different screen densities and sizes.

What is the difference between relative layout linear layout and constraint layout?

Android Layout TypesLinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.

Which is better ConstraintLayout and RelativeLayout?

If you have the choice start with ConstraintLayout, but if you already have your app in RelativeLayout, stay with it. That's all I have been following. RelativeLayout is very limited in functionality and many complex layouts can't be made using it, especially when ratios are involved.

What is the advantage of constraint layout?

Constraint Layout simplifies creating complex layouts in Android by making it possible to build most of your UI using only the visual editor in Android Studio. Constraint Layout comes with some powerful tools with the help of which you can define complex layouts without having deep nesting.


1 Answers

It is not much different than other layouts you are probably already using (like RelativeLayout or LinearLayout). The attributes are very similar to the ones used with Relative Layout.

This is primarily designed as a visually oriented tool. The visual editor is intended to be the main way developers interact with their layouts.

The main goal of this new layout, is to help developers create complex layouts that are optimized to rendez quickly. In fact, its aim is to reduce layout hierarchies induced by other layout types.

like image 196
Belbahar Raouf Avatar answered Oct 16 '22 01:10

Belbahar Raouf