我试图找到这个特定问题的答案,但我找不到。 我看了一个视频https://www.youtube.com/watch?v=NYtB6mlu7vA我的印象是过度使用布局通常很昂贵。 像推特这样的应用程序使用由许多嵌套组 View 组成的复杂设计
我知道这些是 ListView 中的行,它们被回收了,但我的问题是,这通常被认为是不好的做法吗?
他们在视频中讨论了 linearlayout 执行计算以在其中绘制元素的事实,当嵌套多个 linearlayout 时情况会变得更糟。
最佳答案
根据 Lint 检查:
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.
根据我的经验:
如果您的应用支持 api 9+,我建议嵌套 View 少于 12 个。通常这些设备对内存有限制。您可以获得 OutOfMemoryException 或 StackOverflowException。当“复合”模式递归遍历层次结构时,就会发生 StackOverflow。
关于android - 有多少 ViewGroup(LinearLayout、Relative、Grid 等)被认为太多了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40499146/