When should I use ConstraintLayout?

1

In addition to RelativeLayout , FrameLayout , LinearLayout , TableLayout , among others already existing, that greatly meet the needs related to layout , Google announced Google I / O 2016 or ConstraintLayout ". Here is an example:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</android.support.constraint.ConstraintLayout>
  • Noting that it has a lot of similarity to RelativeLayout , what would be the difference between the two?
  • When should I use ConstraintLayout ?
asked by anonymous 26.03.2017 / 03:00

1 answer

2

When you need layouts more complex and you need a more precise hierarchy.

ConstraintLayout was created, according to doc , to create screens with a more precise hierarchy, without having to nest the views . That is, whenever you're going to do a relatively complex layout that needs precise alignment, you have to use ConstraintLayout . The purpose of this view is to allow developers to optimize the hierarchies of their screens.

  

Advantages

  • Optimized for display hierarchies
  • You will have no problem if the visibility state of your view is GONE , the alignment will work anyway and you will no longer worry about broken layouts.
  • Completely user friendly editor
  • Easy to use and designed for responsive screens
  

Disadvantages

  • The layout editor will simply move your views for no reason, this should be caused when we try to move one view and we end up clicking another.
  • Performance. The performance in which views are created is somewhat lower if compared to RelativeLayout or LinearLayout .
  • The main problem is the editor . Over time, you'll realize that the editor does things unexpectedly, so you'll end up preferring to create your layouts manually. I prefer. It's better and a little faster.
26.03.2017 / 04:57