This question already has an answer here:
Why RelativeLayout
replaced to ConstraintLayout
in the default layout file of an android empty activity. I need to know why we should use ConstraintLayout
, what other benefits it provides to us.
As provided by Xaver Kapeller - "The main purpose of the ConstraintLayout is to fix problems with the RelativeLayout, and it does it so well. You can do so many things that were impossible with a RelativeLayout. And you can simplify your layout like you never could before. Additionally, it fixes a long-standing performance issue of the RelativeLayout. The double taxation during the measure/layout phase. So we get better performance, more versatility and much simpler layouts in one nice package."
An additional benefit of using it is that it allows you to create your layouts using a drag and drop style editor visually in a way RelativeLayout couldn't similar to Interface Builder in Xcode.
Constraint Layout: This new layout is a flexible layout manager for your app that allows you to create dynamic user interfaces without nesting multiple layouts. It is distributed as a support library that is tightly coupled with Android Studio and backwards compatible to API Level 9.
At first glance, Constraint Layout is similar to RelativeLayout. However, the Constraint Layout was designed to be used in Studio and it can efficiently express your app design so that you rely on fewer layouts like LinearLayout, FrameLayout, TableLayout, or GridLayout. Lastly, with the built-in automatic constraints inference engine. You can freely design your UI to your liking and let Android Studio do the hard work.
来源:https://stackoverflow.com/questions/37992627/why-go-for-constraints-layout-as-we-already-have-relative-layout