문제

선택한 요소를 S : List Component를 ActionScript로 설정하고 작동하지만 List는 선택한 항목으로 스크롤하지 않습니다. Scrollbar 또는 Mouse로 스크롤해야합니다. 선택한 항목에 자동 스크롤 할 수 있습니까? 감사 !

도움이 되었습니까?

해결책

시도해보십시오 s:List 방법 indexisisvisible (index : int) : void를 보장합니다.

다른 팁

스파크를 위해 :

list.ensureIndexIsVisible(index);

이 기능은 Flex 4+에서 목록 상단으로 스크롤됩니다. 품목의 높이를 고려하여 높이가 다른 항목의 목록에 대해 작동합니다.

private function scrollToIndex(list:List,index:int):void
{
    if (!list.layout)
        return;

    var dataGroup:DataGroup = list.dataGroup;

    var spDelta:Point = dataGroup.layout.getScrollPositionDeltaToElement(index);

    if (spDelta)
    {
        dataGroup.horizontalScrollPosition += spDelta.x;
        //move it to the top if the list has enough items
        if(spDelta.y > 0)
        {
            var maxVSP:Number = dataGroup.contentHeight - dataGroup.height;
            var itemBounds:Rectangle = list.layout.getElementBounds(index);
            var newHeight:Number = dataGroup.verticalScrollPosition + spDelta.y 
            + dataGroup.height - itemBounds.height;
            dataGroup.verticalScrollPosition = Math.min(maxVSP, newHeight);
        }
        else
        {
            dataGroup.verticalScrollPosition += spDelta.y;

        }
    }
}
//try this
this.callLater(updateIndex);//where you want to set the selectedIndex

private function updateIndex():void
{
    list.selectedIndex = newIndex;
    list.ensureIndexIsVisible(newIndex);
}

Flex-3에는 a가 있습니다 scrollToIndex 방법이므로 호출 할 수 있습니다

list.scrollToIndex(list.selectedIndex);

나는 이것이 Flex-4에서도 작동해야한다고 생각합니다.

이것은 나를 위해 효과가있었습니다. 캘리포니아를 사용해야했습니다.

list.selectedItem = "MyTestItem"; //or list.selectedIndex = 10;
this.callLater(updateIndex); //dispatch an update to list

private function updateIndex():void {
    list.ensureIndexIsVisible(list.selectedIndex);
}

여기서이 기본 아이디어를 보았습니다 ...http://arthurnn.com/blog/2011/01/12/coverflow-layout-for-flex-4/

public function scrollGroup( n : int ) : void
{
    var scrollPoint : Point = theList.layout.getScrollPositionDeltaToElement( n );
    var duration : Number = ( Math.max( scrollPoint.x, theList.layout.target.horizontalScrollPosition ) - Math.min( scrollPoint.x, theList.layout.target.horizontalScrollPosition )) * .01;
    Tweener.addTween(theList.layout,{ horizontalScrollPosition: scrollPoint.x , time:duration});
}
protected function theList_caretChangeHandler(event:IndexChangeEvent):void
{
    scrollGroup( event.newIndex );
    event.target.invalidateDisplayList();
}

목록의 스크롤러에 직접 액세스하고 다음과 같은 작업을 수행하고 싶을 것입니다.

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

요소의 높이를 인덱스별로 곱하고이 값을 다음으로 전달할 수 있습니다.

yourListID.scroller.viewport.verticalScrollPosition

그것은 버그입니다 - 당신은 시연과 해결 방법을 볼 수 있습니다. https://issues.apache.org/jira/browse/flex-33660

이 사용자 정의 목록 구성 요소 확장자는 다음과 같습니다.

<s:List
    xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    valueCommit="callLater(ensureIndexIsVisible, [selectedIndex])">
</s:List>

나는 최근에 그룹의 항목에 대한 정의 된 크기를 가지고 내 프로젝트 중 하나에서 이것을 달성했습니다.

<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>

이 후에 개인 "TargetIndex"변수를 증가시켜 조작을위한 내 버튼 컨트롤이 작동 한 다음, 단순화로 콤보에서 utpane.firstindexinview와 target index를 비교 한 콤보에서 아미트 클래스를 사용한 체크 아니 화 함수를 불렀습니다. 이것은 그룹의 "HorizontalsCrollPosition"을 수정했습니다.

이것은 별도의 컨트롤이 본질적으로 스크롤 막대 역할을 할 수 있었지만, 선택한 항목을보기 위해 컨트롤을 슬라이딩해야 할 필요가있었습니다.이 기술은 자동화 된 항목 선택에도 효과가 있다고 생각합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top