ItemRenderer这种东西很常用,很可惜垂直滚动条拖来拖去(特别是还用上了variableRowHeight)可能造成ItemRenderer的位置不正确,错位或者重叠,这似乎是一个bug了,google半天没啥结果(更可惜的是我没有截图看看,哈)。不单单是List,只要基于ListBase的都有可能。在我自己的案子里,我使用了variableRowHeight=true的List,ItemRenderer是一个VBox,包含了Text和几个Button。每段文字各不相同。
原因
说实话我没看过源码也不是非常清楚。flex framework从效率上考虑,ItemRenderer不是一次性全部渲染掉的,比如List只能显示两个ItemRenderer,那只会渲染这两个,如果滚动显示了其它,就会渲染其它的ItemRenderer,这个过程比较复杂,以后有空好好研究下。
方案
既然是滚动条,就从滚动条上下手。List继承自ListBase,ListBase来自ScrollControlBase,ScrollControlBase就是处理滚动特性的基类,它有一个protected方法scrollHandler,是用来处理滚动事件的。下面要做的事情就简单了。只要在scrollHandler函数里加上点东西,来保证ItemRenderer位置正确。很可惜这块的原理我也不是很明确,只是在实验的时候发现RESIZE可以重画List,其实它对应的调用updateList方法(ListBase的protected方法),这样位置就会调整正确了。来看看updateList的注释:
Refreshes all rows now. Calling this method can require substantial processing, because can be expensive at it completely redraws all renderers in the list and won’t return until complete.
看看重新扩展的List
package myvocal.visual { import flash.events.Event; import mx.controls.List; import mx.events.*; public class MyList extends List { public function MyList() { //TODO: implement function super(); } protected override function scrollHandler(event:Event):void { trace("onUserScroll") super.scrollHandler(event); this.updateList() } } }
搞定!
相关推荐
通过两种方法继承List组件的IconItemRenderer,实现在每个item项中添加组件,如button等
flex中经常会使用到渲染器,这里简要介绍一下渲染器的一些知识
详细介绍Flex的项目呈现器的各种初级用法以及高级用法,相当实用。
关于flex的itemRenderer的介绍,还算比较详细。
理解_Flex_itemRenderer 理解_Flex_itemRenderer 理解_Flex_itemRenderer
提供: 内渲染器的使用方法。 通过2个List的 界面 自己看效果理解。
用FLEX4做的项呈现器,仿雅虎聊天界面。 需要的字段为userId、nikeName、sex…… 你可以自行添加 声明,次呈现器只做模版使用。
解决Flex内联itemRenderer的例子
itemRenderer里面的内容 获取技巧。
There is the List control itself, the DataGrid, the Tree, and the visualization classes, which include the charts and the AdvancedDataGrid. By default, the Flex list controls display the data they ...
checkbox和combobox作为DataGrid的itemRenderer和headerRenderer 包括全选,多选,等。。。
flex itemRenderer 渲染机制的概念和使用
Flex项呈示器自定义及使用实例,展示用户信息,包括头像及等级信息。与博客Flex之旅--项呈示器ItemRenderer对应
提供: ActionScript 自定义 ItemRenderer 渲染器的基本方法 与上一个例子 效果一样。
NULL 博文链接:https://taomujian.iteye.com/blog/316882
随意分叉该项目并解决您可能遇到的任何未解决的问题,我们最终将尝试合并相关的更改。 我们对不便表示抱歉。 史密斯探员: ...我们别无选择,只能按计划进行。 部署哨兵。 立即地。 React Intersection List建立...
FLEX4实践—动态生成DataGrid及应用客户化itemRenderer.doc
NULL 博文链接:https://liugang-ok.iteye.com/blog/1135551
NULL 博文链接:https://iamcloo.iteye.com/blog/1164571
NULL 博文链接:https://baiyejianxin.iteye.com/blog/823229