Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constraint Layout instead of Relative Layout

In new Android Studio 2.2 the Constraint Layout is introduced, I had searched and read about this new layout here and here. and in this link I had read about differences between Constraint and Relative layouts, but still some questions remain:

  1. Can we replace RelativeLayout with ConstraintLayout completly, as mentioned here?
  2. Do devices with old versions can support ConstraintLayout?
  3. For designing apps with ConstraintLayout we have to update to Android Studio 2.2?
  4. with using ConstraintLayout we don't need to write many dimens.xml for all screen resolution to have a responsive app?
like image 948
Shima Erfan Avatar asked Sep 25 '16 08:09

Shima Erfan


People also ask

Why constraint layout is better than 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.

Should I use constraint layout or relative layout?

Note: For better performance and tooling support, you should instead build your layout with ConstraintLayout. A RelativeLayout is a very powerful utility for designing a user interface because it can eliminate nested view groups and keep your layout hierarchy flat, which improves performance.

Why do we prefer constraint layout?

Advantages of using ConstraintLayout in AndroidIt helps to improve the UI performance over other layouts. With the help of ConstraintLayout, we can control the group of widgets through a single line of code. With the help of ConstraintLayout, we can easily add animations to the UI components which we used in our app.

How do I change a relative layout to constraint layout?

Convert a layout To convert an existing layout to a constraint layout, follow these steps: Open your layout in Android Studio and click the Design tab at the bottom of the editor window. In the Component Tree window, right-click the layout and click Convert layout to ConstraintLayout.


2 Answers

  1. ConstraintLayout does all that RelativeLayout does, and more
  2. It's supported starting from API level 9 (Gingerbread) -- ie. 99.9% of devices
  3. Yes. You can edit the XML by hand too, but the editor in 2.2 is recommended
  4. It depends what you want to do -- using dimens might still be useful (for example, you might want roughly the same layout, but with different margins).
like image 157
Nicolas Roard Avatar answered Sep 19 '22 09:09

Nicolas Roard


The another fact good to know is that ConstraintLayout provides much better performance than RelativeLayout. Especially nested RelativeLayouts can make your performance worse.

like image 25
Tom Wayne Avatar answered Sep 20 '22 09:09

Tom Wayne