Scroll to selected item in Flex 4 Spark List compo

2019-01-23 11:36发布

I'm setting selected element in s:List component with Actionscript, it works, but List doesn't scroll to selected item -- need to scroll with scrollbar or mouse. Is it possible to auto-scroll to selected item ? Thanks !

12条回答
姐就是有狂的资本
2楼-- · 2019-01-23 12:11

This custom List component extension worked for me:

<s:List
    xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    valueCommit="callLater(ensureIndexIsVisible, [selectedIndex])">
</s:List>
查看更多
Explosion°爆炸
3楼-- · 2019-01-23 12:13

I recently accomplished this in one of my projects by having a defined size for my items in the group..

<s:Scroller x="940" y="0" maxHeight="465" maxWidth="940" horizontalScrollPolicy="off" verticalScrollPolicy="off">
  <s:HGroup  id="tutPane" columnWidth="940" variableColumnWidth="false" gap="0" x="0" y="0">
  </s:HGroup>
</s:Scroller>

Following this my button controls for manipulation worked by incrementing a private "targetindex" variable, then I called a checkAnimation function, which used the Animate class, in combo with a SimpleMotionPath and a comparison between tutpane.firstIndexInView and target index. This modified the "horizontalScrollPosition" of the group.

This allowed separate controls to essentially act as a scroll bar, but I had the requirement of sliding the control to view the selected item.. I believe this technique could work for automated selection of items as well

查看更多
Anthone
4楼-- · 2019-01-23 12:14
//try this
this.callLater(updateIndex);//where you want to set the selectedIndex

private function updateIndex():void
{
    list.selectedIndex = newIndex;
    list.ensureIndexIsVisible(newIndex);
}
查看更多
做个烂人
5楼-- · 2019-01-23 12:15

You'll probably want to access the List's scroller directly and do something like:

list.scroller.scrollRect.y = list.itemRenderer.height * index;

查看更多
霸刀☆藐视天下
6楼-- · 2019-01-23 12:16

For Spark:

list.ensureIndexIsVisible(index);

查看更多
该账号已被封号
7楼-- · 2019-01-23 12:20

It is a bug - you can see the demonstration and a workaround at the https://issues.apache.org/jira/browse/FLEX-33660

查看更多
登录 后发表回答