为什么嵌套的权重不好的表现?备择方案? [英] Why are nested weights bad for performance? Alternatives?

查看:339
本文介绍了为什么嵌套的权重不好的表现?备择方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写在这里我使用了 layout_weight 属性来创建不同意见之间的比率一对夫妇布局文件。

I have written a couple layout files where I used the layout_weight attribute to create a ratio between different views.

在某些时候,我开始变得lint警告有关嵌套的权重。

At some point, I start getting lint warnings about nested weights.

所以,我不知道为什么被嵌套权重坏的性能,而且,如果有一个更有效的方式来创建可用于不同的屏幕尺寸,并且不需要指定很多视图尺寸之间的恒定比率throught几个布局文件(适用于不同的屏幕尺寸,我的意思)维DPI值。

So, I wonder why are nested weights bad for performance, and if there is a more efficient way to create a constant ratio between view dimensions that could be used for different screen sizes and that doesn't need to specify a lot of dimension dpi values throught several layout files (for different screen sizes, I mean).

感谢您!

推荐答案

嵌套重量是不好的性能,因为:

Nested weights are bad for performance because:

布局权重需要一个小部件要被测量两次。当一个   的LinearLayout具有非零权重被嵌套在另一个   的LinearLayout具有非零权重,测量然后数   成倍增加。

Layout weights require a widget to be measured twice. When a LinearLayout with non-zero weights is nested inside another LinearLayout with non-zero weights, then the number of measurements increase exponentially.

它总是最好使用<一个href="http://developer.android.com/resources/tutorials/views/hello-relativelayout.html">RelativeLayouts并根据其他意见的地方调整您的视角,而无需使用特定的DPI值。

It's always better to use RelativeLayouts and adjust your view according to the places of other views without using specific dpi values.

这篇关于为什么嵌套的权重不好的表现?备择方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆