Search code examples
androidperformanceandroid-support-libraryandroid-percentrelativelayout

PercentRelativeLayout is more Performant?


I always use LinearLayout and RelativeLayouts, and i was reading about the "new" PercentRelativeLayout. I have a few questions:

  • Should i always start using this one or only in cases of nested weights with linearlayout?

  • Is this more performant than the others?

Any other information about PercentRelativeLayout it will be welcome.

Thanks!


Solution

  • Looking at the source code, a PercentRelativeLayout is basically a minor extension of a RelativeLayout. This means you need to make the same considerations as when you choose between a RelativeLayout and LinearLayout.

    • RelativeLayout needs 2 measure passes -> avoid using it as the root of a deep view hierarchy or nesting multiple RelativeLayouts (more info in this stackoverflow post)
    • Layout weights in LinearLayout also require 2 measure passes -> try to replace these constructs as much as possible with one Relative/GridLayout (more info in this stackoverflow post)

    Finally it is worth noting that:

    • Don't optimise unless you have a problem
    • Try to keep your hierarchies as flat as possible