Reputation: 123
I am creating complex layouts with many Views on various screens of my app.The documentation says that:
It is a common misconception that using the basic layout structures leads to the most efficient layouts. However, each widget and layout you add to your application requires initialization, layout, and drawing. For example, using nested instances of LinearLayout can lead to an excessively deep view hierarchy. Furthermore, nesting several instances of LinearLayout that use the layout_weight parameter can be especially expensive as each child needs to be measured twice.
So an alternative is to use Relative Layout or Constraint layout. This late 2018 article says Relative layout is better.
Today in terms of performance which one is better? Relative layout or Constraint layout?
Upvotes: 11
Views: 11190
Reputation: 119
Note that the late 2018 article referenced in the question discusses the performance of RelativeLayout vs nested LinearLayouts and doesn't mention ConstraintLayout. ConstraintLayout has a better performance since it's introduced. A performance benchmark of ConstraintLayout vs RelativeLayout is available in this official blog post by Google - ConstraintLayout is ~40% faster.
Upvotes: 4
Reputation: 1688
I would use the constraint layout. It shall perform better.
In the N release of Android, the ConstraintLayout class provides similar functionality to RelativeLayout, but at a significantly lower cost.
Quote from performance/rendering/optimizing-view-hierarchies at the bottom
Upvotes: 9