为什么嵌套权重对性能不利?备择方案? [英] Why are nested weights bad for performance? Alternatives?

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

问题描述

我编写了几个布局文件,其中使用了 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.

所以,我想知道为什么嵌套权重对性能不利,是否有更有效的方法来创建可用于不同屏幕尺寸的视图尺寸之间的恒定比率,并且不需要指定很多尺寸 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.

最好使用 RelativeLayouts 并调整您的视图根据其他视图的位置,不使用特定的 dpi 值.

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

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

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