How many ViewGroup (LinearLayout, Relative, Grid, etc..) considered too many?

Deadly 提交于 2020-01-05 06:55:13

问题


I tried to find an answer for this specific question but I couldn't. I watched a video https://www.youtube.com/watch?v=NYtB6mlu7vA and I got the impression that over using Layouts generally is expensive. Apps like twitter, use complex designs that consists of many nested group views

I realize that these are rows inside a listview, and they are recycled, but my question is, is this considered bad practice generally?

The video they discussed the fact that linearlayout performs a calculation to draw elements inside it, and it gets worse when you nest multiple linearlayouts.


回答1:


According to Lint Checks:

Layout has too many views

The maximum view count defaults to 80 but can be configured with the environment variable ANDROID_LINT_MAX_VIEW_COUNT.

Layout hierarchy is too deep

Layouts with too much nesting is bad for performance. Consider using a flatter layout (such as RelativeLayout or GridLayout).The default maximum depth is 10 but can be configured with the environment variable ANDROID_LINT_MAX_DEPTH.

According to my experience:

If your app supports api 9+ I recommend having less than 12 nested views. Usually these devices have limitations on memory. You can get OutOfMemoryException or StackOverflowException. StackOverflow happens when "Composite" pattern recursively walks through hierarchy.



来源:https://stackoverflow.com/questions/40499146/how-many-viewgroup-linearlayout-relative-grid-etc-considered-too-many

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!