Flex中实现tree水平滚动条自动加载
Flex中实现tree水平滚动条自动加载
flex中的tree有一个horizontalScrollPolicy的属性,值可以用三个:on,off,auto。
on:表示水平滚动条一直都出现
off:表示去除水平滚动条
auto:顾名思义。就是自动加载水平滚动条
然而,在自定义了一个树形列表控件后,设置horizontalScrollPolicy=“auto”。水平滚动条并没有自动加载,经过查资料,原来需要在自定义控件中重载下列三个方法,方法如下:
override public function get maxHorizontalScrollPosition():Number{if (isNaN(mx_internal::_maxHorizontalScrollPosition)) return 0; return mx_internal::_maxHorizontalScrollPosition; } override public function set maxHorizontalScrollPosition(value:Number):void{mx_internal::_maxHorizontalScrollPosition = value; dispatchEvent(new Event("maxHorizontalScrollPositionChanged")); scrollAreaChanged = true; invalidateDisplayList(); }override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{ var diffWidth:Number = measureWidthOfItems(0,0) - (unscaledWidth - viewMetrics.left - viewMetrics.right);var indentation:Number = getStyle("indentation");if (diffWidth <= 0) maxHorizontalScrollPosition = NaN;elsemaxHorizontalScrollPosition = diffWidth + indentation; super.updateDisplayList(unscaledWidth, unscaledHeight); }