有多少个ViewGroup(LinearLayout,Relative,Grid等)认为太多? [英] How many ViewGroup (LinearLayout, Relative, Grid, etc..) considered too many?
问题描述
我试图找到针对此特定问题的答案,但没有。
我观看了一个视频
我意识到这些是列表视图中的行,并且已被回收,但是我的问题是,这通常被认为是不好的做法吗?
他们的视频讨论了linearlayout执行计算以在其中绘制元素的事实,当您嵌套多个linearlayouts时,情况会变得更糟。
根据Lint检查:
布局视图太多
最大视图数默认为80,但可以使用环境变量ANDROID_LINT_MAX_VIEW_COUNT进行配置。
布局层次结构也是如此deep
嵌套过多的布局会降低
的性能。考虑使用更平坦的布局(例如
RelativeLayout或GridLayout)。默认最大深度为10,但可以使用环境变量ANDROID_LINT_MAX_DEPTH配置
。
根据我的经验:
如果您的应用支持api 9+,我建议嵌套视图少于12个。通常,这些设备对内存有限制。您可以获取OutOfMemoryException或StackOverflowException。当复合模式递归遍历层次结构时,就会发生StackOverflow。
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.
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.
这篇关于有多少个ViewGroup(LinearLayout,Relative,Grid等)认为太多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!