问题
I have:
- an ArrayCollection of Numbers;
- a List using the above ArrayCollection as it's dataprovider, and virtualLayout=true;
- a custom ItemRenderer that shows a label with: a) the number b) an y position depending on the number AND the highest number visible
In another words, if I have 10 numbers in the AC, and only 5 appear on the screen, the y position of those 5 will depend on the value of the maximum number for those 5. When the user scrolls, of course those 5 elements change so the position of the label in item renderers will change.
My questions:
1) How can I get the list of items that are "currently" visible? 2) Which event/method to override will help me know that the List was scrolled/the visible items changed?
Thank you,
João Saleiro
回答1:
getItemIndicesInView():Vector.<int>
Return the indices of the item renderers visible within this DataGroup.
回答2:
I have solved my problem this way:
protected function pagedList_touchInteractionEndHandler(event:TouchInteractionEvent):void
{
var _index:int = (event.currentTarget.scroller.viewport.layout.horizontalScrollPosition / event.currentTarget.scroller.viewport.layout.columnWidth);
}
<s:List id="pagedList" scrollSnappingMode="center" selectionColor="#FFFFFF" downColor="#FFFFFF" focusAlpha="0"
width="100%" height="100%" useVirtualLayout="true"
verticalScrollPolicy="off" horizontalScrollPolicy="on"
pageScrollingEnabled="true"
itemRenderer="myItemRender"
skinClass="skins.PagedListSkin"
touchInteractionStart="pagedList_touchInteractionStartHandler(event)" touchInteractionEnd="pagedList_touchInteractionEndHandler(event)" >
<s:layout>
<s:TileLayout orientation="rows" requestedRowCount="1"
columnWidth="{pagedList.width}" rowHeight="{pagedList.height}"
verticalGap="0" horizontalGap="0" />
</s:layout>
</s:List>
回答3:
((list.dataGroup.layout) as VerticalLayout).rowCount
might be just what you're looking for.
来源:https://stackoverflow.com/questions/2621716/how-to-get-the-visible-items-on-a-spark-list-with-virtual-layout