ConstraintLayout vs. “traditional” layouts

I'm just wondering when to choose CoordinatorLayout over the "traditional" layouts or will they (or at least some of them) become obsolete?

Question ConstraintLayout vs. CoordinatorLayout has already shown me that the Layout coordinator still has a right to exist. I would suggest that FrameLayout is still a better choice than ConstraintLayout when there is only one child view.

But what about other layouts?

I personally am so used to writing layouts manually in xml, so the transition to ConstraintLayout is very difficult for me. Moreover, the answers to these questions really interest me:

Does ConstraintLayout have better performance than nested layout? If so, at what point does this happen (what level of nesting)?

+14
android android-layout
source share
4 answers

I'm just wondering when to choose CoordinatorLayout over the "Traditional" layouts or are they (or at least some of them) going to be deprecated?

So ConstraintLayout is useful, but (for now) it is not required for Android application development, any more than LinearLayout and RelativeLayout . And since ConstraintLayout is a library, you will need to take additional steps to add it to your project ( com.android.support.constraint:constraint-layout artifact com.android.support.constraint:constraint-layout in your closing dependencies of your build.gradle file modules), and this adds ~ 100 KB to the size of your Android application.

I personally am so used to writing layouts manually in xml, so the transition to ConstraintLayout is very difficult for me.

Drag and Drop GUI Constructor

Google is trying to simplify the life of developers and make them work faster and more productively, so they continue to improve the drag-drop GUI builder. However, the drag and drop gestures, the developer only providing you the X / Y coordinates of the widget, based on where the developer releases the mouse button and completes the drop. With LinearLayout adding a widget is very simple. Using the RelativeLayout for the GUI controller is difficult to handle drag and drop, and you probably have to dig inside the XML code to get it done. ConstraintLayout was created with GUI in mind, to make it a little easier to derive the correct rules based on where the developer removes the widget.

Recompilation of size and position

Changing widget details often causes dimensions to be recounted. For example, a change in the TextView may have the whole hierarchy go through the work of redistributing / re-positioning. If you have a container inside a container that is inside another container, etc., This means that parents are resizing / redefining their children, and this can be very expensive for deep hierarchies. So

Does ConstraintLayout have higher performance than nested Layout?

Yes, ConstraintLayout designed for performance, trying to eliminate as many passing scenarios as possible, and trying to eliminate the need for deeply nested view hierarchies.

Yes,

For more information, see CommonsWare’s Android Development Book . Where the use of ConstraintLayout is explained in more detail with comparison examples with other containers such as LinearLayout , RelativeLayout , etc. Indeed, the anatomy of android development.

+11
source share

I would suggest that FrameLayout is still a better choice than ConstraintLayout when there is only one child view.

I think the power of ConstraintLayout really takes place when you go beyond simple layouts. I think the goal (at least for me) is to smooth out your complex layout as much as possible. Using a complete set of ConstraintLayout , such as invisible constraints such as Guideline and Barrier , to specify vertical / horizontal layout_constraintVertical_bias and view distributions using layout_constraintVertical_chainStyle .

If you have a complex view with nested ViewGroup s, start using ConstraintLayout .

I personally am so used to writing layouts manually in xml, so the transition to ConstraintLayout is very difficult for me.

This is also true for me. I used to write layouts of xml files manually, and I'm still doing with ConstraintLayout . The editor is much improved, and I use it mainly to make sure that the constraints look right. There was little time to get used to writing xml manually, but as soon as you go, I’m much sure about this, and then the editor will add material that you may not suspect.

Another reason for using ConstraintLayout : a great way to implement animation without too much manual coding with ConstraintSet . Some great example: https://robinhood.engineering/beautiful-animations-using-android-constraintlayout-eee5b72ecae3

+4
source share

You can continue to use other layouts for simple things (if they are not outdated), but ConstraintLayout is faster, smarter and yes, have better performance than RelativeLayout.

You can check this answer which talks about the differences between ConstraintLayout and RelativeLayout

+2
source share

I will try to answer your questions. And I assume that you are talking about layouts in Android development.

Firstly, you can still use all the layouts of Relative, Linear, Frame, etc. They are not yet depreciated by the Android platform. From my own experience, I know that ConstrainLayout is a little difficult to code manually in xml, but if you use the constraint layout, Android Studio provides some pretty interesting drag and drop tools. Tools can practically do what you usually do in XML manually. In addition, they are very productive and save a lot of your time.

In terms of performance, one of the deadly and costly operations in Android is to render views, especially when complex tree views are used inside list or processor views. Sophisticated tree views, which are usually designed with a linear or relative layout, are expensive to compute and visualize. A constraint scheme preserves and helps solve these problems.

I highly recommend looking at the official Android documentation for an additional link in the following link.

https://developer.android.com/training/constraint-layout/

0
source share

All Articles