Skip to content

Flex measure深入

ythy edited this page Jan 8, 2018 · 1 revision

概念

  1. width: 组件的宽度,有可能是显式设置的lbl.width = 100,也有可能是测量的lbl.setActualSize(100, xx)
  2. measuredWidth: 组件的默认宽度,在绘制周期的measure()方法里设置
  3. ExplicitWidth: 组件的显示宽度,通过lbl.width = 100 设置,否则是NaN
  4. getExplicitOrMeasuredWidth(): 返回组件的ExplicitWidth || measuredWidth

疑难

  1. measure() 阶段如果组件在createChildren()没有显示设置宽度,lbl.width在测量之前是0, 应当取measuredWidth
  2. updateDisplayList() 阶段实例
 trace(btn.height + " " + btn.getExplicitOrMeasuredHeight()) ;
 btn.height = 50;
 trace(btn.height + " " + btn.getExplicitOrMeasuredHeight()) ;
 输出为
 0 22
 50 50
 trace(btn.height + " " + btn.getExplicitOrMeasuredHeight()) ;
 btn.setActualSize(100, 50)
 trace(btn.height + " " + btn.getExplicitOrMeasuredHeight()) ;
 输出为
 0 22
 50 22

说明 显式或测量设置高度,都会改变组件的高度,显示设置高度后getExplicitOrMeasuredHeight() 返回值对应发生变化

Clone this wiki locally