RelativeLayout measures all its children twice. This can cause performance issues. Does constraint layout only measure its children once each?
More complex layout but results are the same, flat Constraint Layout is slower than nested Linear Layout.
A ConstraintLayout is a ViewGroup which allows you to position and size widgets in a flexible way. Note: ConstraintLayout is available as a support library that you can use on Android systems starting with API level 9 (Gingerbread). As such, we are planning on enriching its API and capabilities over time.
This is because ConstraintLayout allows you to build complex layouts without having to nest View and ViewGroup elements. When running the Systrace tool for the version of our layout that uses ConstraintLayout , you see far fewer expensive measure/layout passes during the same 20-second interval.
ConstraintLayout has dual power of both Relative Layout as well as Linear layout: Set relative positions of views ( like Relative layout ) and also set weights for dynamic UI (which was only possible in Linear Layout). Despite the fact that it's awesome, it fails to serve the purpose with simple UI layouts.
ConstraintLayout
requires up to two measure passes.
If you look at the ConstraintLayout
's source, you'll see that its onMeasure()
method first measures its children inside an internalMeasureChildren()
utility method. Next, it evaluates some constraints. Finally, ConstraintLayout
calls child.measure()
on its children a second time inside a loop.
Source: decompiled the class files, since the source isn't available at this time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With