Maximum number of LinearLayout that can be nested in one XML file?

What is the maximum number of LinearLayouts that can be nested? Is it infinite, or is there a limitation that Android studio emphasizes? Or is it device dependent?

+3


source to share


2 answers


Tree depth mapping is, in practice, limited by the size of the UI element stack, which is required to recursively traverse the view tree in measure / draw operations. The stack size depends on the API level and is 8kB, 12kB, or 16kB. There is no specific number as a depth limit; in practice you will see StackOverflowError

in low complexity devices after a few dozen or so nested views.

Lint will nag if you have nesting level 10 or deeper in the same layout file. It does not parse the depth of the run-time layout hierarchy.



Think about how to keep your view hierarchy as flat as possible.

+7


source


Deep layouts . Overly nested layouts don't work well.

Consider using flatter layouts such as a RelativeLayout or GridLayout to improve performance.

The default maximum depth is 10 .



Read on for more information.

+3


source







All Articles