M
M
mitaichik2019-05-31 21:09:48
Android
mitaichik, 2019-05-31 21:09:48

What's with the performance of RelativeLayout / ConstraintLayout?

Hello!
I have one list (RecyclerView) where each item has a rather complex layout (about 40 linearlayouts, textviews, etc.)
It is laid out rather clumsily - LinerLayout and TableLayout are everywhere (this is generally the first layout I have made, do not blame me).
Now I'm limiting it, and now I'm thinking of using RelativeLayout / ConstraintLayout.
Question: are they more productive than a bunch of nested LinearLayouts (in some places with given layout_weight)?
Because now, on older phones, scrolling through the list sometimes slows down, not very noticeable, but not pleasant.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2019-05-31
@mitaichik

Relative/Constraint will be faster than a bunch of Linears with weights. The weights are important here, as they give a second pass through Linear's children, and negate its simplicity. Nesting is always bad.
In fact, I can express an unpopular opinion - if there is a complex layout inside the Recycler, and this layout is not generalized, but very specific, then it makes sense to think about making it custom. That is, inherit from ViewGroup, add a view (addView) and implement onMeasure/onLayout. Done right, it will be 100% faster than any general purpose layout.
For myself, I deduced a rule of thumb - there is no place for Constraint inside Recycler. Brakes.

I
illuzor, 2019-05-31
@iLLuzor

The fewer levels of nesting, the higher the performance.
It is more convenient to work with ConstraintLayout and it is faster than RelativeLayout, but not much and not always.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question