When should I use Constraintlayout?

Asked

Viewed 1,077 times

1

Beyond the RelativeLayout, FrameLayout, LinearLayout, TableLayout, among others already existing, which sufficiently meet the needs related to layout, Google announced on Google I/O 2016 the ConstraintLayout. See below for 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 bears much resemblance to RelativeLayout, what would be the difference between the two?
  • When should I use the ConstraintLayout?

1 answer

2

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

The ConstraintLayout was created in accordance with the doc, to create screens with a more precise hierarchy, without having to nest views. That is, whenever you are going to make a layout relatively complex and that needs an accurate alignment, you have to use ConstraintLayout. The purpose of this view is just that, to allow developers to optimize the hierarchies of their screens.

Perks

  • Optimized for display hierarchies
  • You will not have problems if the visibility status of your view for GONE, alignment will work anyway and you will no longer worry about broken layouts.
  • Completely friendly editor
  • Easy to use and made to draw responsive screens

Disadvantages

  • The layout editor will simply move your views for no reason, this should be caused when we try to move a view and end up clicking on another one.
  • Performance. The performance in which views are created is slightly lower than RelativeLayout or LinearLayout.
  • The main problem is the editor. Over time, you will realize that the editor does unspeakable things, so you will end up preferring to create your layouts manually. I prefer it. It’s better and a little faster.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.