What is the maximum number of LinearLayouts that can be nested ? Is it infinite, or is there a limit that Android-studio emphasizes ? Or is that device dependent?
View tree depth is in practice limited by the UI thread stack size that is needed for the recursive traversal of the view tree in measure/draw operations. The stack size depends on the API level and is 8kB, 12kB or 16kB. There isn't a specific number as the depth limit; in practice you'll see StackOverflowError
s in low-spec devices after a couple dozen nested views or so.
Lint will nag if you have nesting level 10 or deeper in a single layout file. It doesn't analyze the runtime layout hierarchy depth.
Consider keeping your view hierarchies as flat as possible.
Deep layouts - Layouts with too much nesting are bad for performance.
Consider using flatter layouts such as RelativeLayout or GridLayout to improve performance.
The default maximum depth is 10.
Have a read for more information.
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