RelativeLayout vs. Nested Linear Layout

I have heard for a long time that RelativeLayouts are slow. In a couple of conversations, I recall that this type of layout calls onMeasure twice, and for some reason it drag on performance.

However, I am taking a performance course on udacity, and I watched the following video:

https://www.youtube.com/watch?time_continue=303&v=gK9tdeqqigE

Here, the instructor used the hierarchy view tool to compare the rendering cost of the same view group using relative layout and nested linear layouts.

In the video, relativelayout is a clear winner, which contradicts everything that I have heard so far about the problem.

Could you help me understand the circumstances under which each approach is best?

thank

+4
source share
1 answer

This is a very broad question, and there is no single simple answer. LinearLayout is usually simpler (and therefore faster) than RelativeLayout, but LinearLayout has a problematic case if you insert several of them into each other, with weights on the same axis. Then it must iteratively divide the space, and this takes many passes of the layout (so bad that there was no warning about this).

Even when you avoid this case, then with LinearLayouts nested you will still have a deeper hierarchy of views compared to using RelativeLayout, so while LinearLayout is faster, which at some point balances.

, , : , , .

+8

Source: https://habr.com/ru/post/1655003/


All Articles