Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum number of LinearLayout's that can be nested in a single XML file?

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?

like image 756
OBX Avatar asked Dec 15 '22 14:12

OBX


2 Answers

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 StackOverflowErrors 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.

like image 137
laalto Avatar answered Jan 07 '23 11:01

laalto


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.

like image 35
Don Chakkappan Avatar answered Jan 07 '23 11:01

Don Chakkappan