我有两个 View ,它们在我的主布局上均匀分布。但是我在 tern 的两个 View 有嵌套的 subview ,它们的间距也相等。我正在使用嵌套布局权重,它工作正常。嵌套权重是否会影响性能。解决这个问题的方法是什么?
最佳答案
Every view — or worse, every layout manager — that you add to your application comes at a cost: initialization, layout and drawing become slower. The layout pass can be especially expensive when you nest several LinearLayout that use the weight parameter, which requires the child to be measured twice.
引用:http://developer.android.com/resources/articles/layout-tricks-efficiency.html
在大多数情况下,您可以使用 RelativeLayout 来避免这种昂贵的测量。在 RelativeLayout 中, View 与其父 View 、RelativeLayout 本身或其他 View 对齐。
为了清楚地了解 View 是如何相对于彼此定位的,可以使用 Android SDK 的 HierarchyViewer 透视图来捕获布局的线框。
关于android - 用于相等间距和性能的嵌套布局权重,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8629376/