android - 用于相等间距和性能的嵌套布局权重

标签 android android-layout android-widget

我有两个 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/

相关文章:

android - 如何为 ListView 中的每一行设置不同的背景颜色?

android - 获得布局高度的最佳位置是什么?

android - 删除要从 Android 键盘输入的表情符号

android - onGetViewFactory 未调用

android - 如何以编程方式更改 ListView 高度..?

android - 像YouTube应用一样叠加显示

android - 仅针对 Android 7.0 向 HTTPS 服务器发出请求时,React native fetch() 失败

android - 当应用程序来自后台时总是触发观察者

Android:如何在方向更改时保存自定义手指绘画 View

java - 在android中居中我的线性布局