【问题标题】:What is better for perfomance width="100%" or left="0" right="0"?性能 width="100%" 或 left="0" right="0" 哪个更好?
【发布时间】:2012-06-09 09:32:30
【问题描述】:

在最新的 Adob​​e Flex sdk 4.6 中,从性能角度来看,哪个更好?

<s:Group width="100%" height="100%"/>

<s:Group left="0" right="0" top="0" bottom="0"/>

谢谢。

【问题讨论】:

  • 我真的不知道,但我相当肯定差异充其量只是微不足道的。
  • 我什至不知道你会如何测试它;我怀疑可能涉及许多因素。什么是布局类型?该组的孩子是什么?宽度和高度——或者在你的例子中是百分比宽度和百分比高度——是属性,而左/右/上/下是样式。设置left/right/top/bottom永远不会绕过measure方法;但是设置宽度和高度会。不过,我不确定要设置 percentWidth 和 percentHeight。 MXML使用烟雾和镜子来设置percentWidth & percentHeight;这正是你的代码要做的。

标签: performance apache-flex mxml


【解决方案1】:

BasicLayout.updateDisplayList() 我发现了这个(在每个子元素的循环中):

if (!isNaN(percentWidth))
            {
                var availableWidth:Number = unscaledWidth;
                if (!isNaN(left))
                    availableWidth -= left;
                if (!isNaN(right))
                     availableWidth -= right;

                childWidth = Math.round(availableWidth * Math.min(percentWidth * 0.01, 1));
                elementMaxWidth = Math.min(layoutElement.getMaxBoundsWidth(),
                    maxSizeToFitIn(unscaledWidth, hCenter, left, right, layoutElement.getLayoutBoundsX()));
            }
            else if (!isNaN(left) && !isNaN(right))
            {
                childWidth = unscaledWidth - right - left;
            }

高度也一样。

所以,看起来像:

  1. percenWidth 的优先级高于 topleft(如果两者都设置)
  2. topleftpercenWidth 更容易计算(单次减法对轮、函数调用和条件)
  3. topleft 可以用作样式声明。

此外,大多数 Flex4 皮肤都是基于 topleft - 我认为也是出于性能原因。

【讨论】:

  • 好帖子。还要说的一件事是 left 将告诉组件与父级左侧的距离。百分比宽度只会告诉它在宽度上将占用多少父级。根据您使用它的情况,您可能会得到不同的结果。
猜你喜欢
  • 2011-05-25
  • 1970-01-01
  • 2020-08-01
  • 2010-09-23
  • 2011-03-28
  • 2015-11-05
  • 1970-01-01
  • 2015-01-23
相关资源
最近更新 更多