Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash ensureIndexIsVisible(),是否滚动到列表控件的顶部?_Flash_List_Flex4 - Fatal编程技术网

Flash ensureIndexIsVisible(),是否滚动到列表控件的顶部?

Flash ensureIndexIsVisible(),是否滚动到列表控件的顶部?,flash,list,flex4,Flash,List,Flex4,我正在使用FB4,显然我需要使用ensureIndexIsVisible()滚动到我的s:List中的特定项目。无论如何,下面的代码成功地滚动到该项目,但没有滚动到列表的顶部(它在底部,并被截断)。有什么办法吗 MXML: AS3: 受保护函数creationCompleteHandler(事件:事件):无效{ 变量d:日期=新日期(); 今日变量:String=String((d.month+1)+“/”+d.date+“/”+d.fullYear); var dP:XMLListColl

我正在使用FB4,显然我需要使用
ensureIndexIsVisible()
滚动到我的
s:List
中的特定项目。无论如何,下面的代码成功地滚动到该项目,但没有滚动到列表的顶部(它在底部,并被截断)。有什么办法吗

MXML:


AS3:

受保护函数creationCompleteHandler(事件:事件):无效{
变量d:日期=新日期();
今日变量:String=String((d.month+1)+“/”+d.date+“/”+d.fullYear);
var dP:XMLListCollection=event.currentTarget.dataProvider;
for(变量i:uint;i
这是个糟糕的解决方案,但对我来说是可行的

var pt:Point = list.layout.getScrollPositionDeltaToElement(i);
while (pt) {
    list.validateNow();
    if (pt.y > 0) {
        var delta:int = list.layout.getVerticalScrollPositionDelta(NavigationUnit.DOWN);
    } else {
        delta = list.layout.getVerticalScrollPositionDelta(NavigationUnit.UP);
    }
    list.layout.verticalScrollPosition += delta;
    pt = list.layout.getScrollPositionDeltaToElement(i);
}

我们能够想出一个更简单的解决方案——在这里发布,因为似乎没有其他人在网上发布过类似的内容

spark.layouts.supportClasses.LayoutBase#getScrollPositionDeltaToElementHelper方法允许传入topOffset,但默认实现传递NaN。如果创建将“0”作为topOffset传递的自定义布局,则在列表上调用ensureIndexIsVisible将导致该索引处的项顶部对齐

请参见下面的自定义布局类:

public class ScrollToElementVerticalLayout extends VerticalLayout
{   
    public override function getScrollPositionDeltaToElement(index:int):Point
    {
        // pass 0 as the topOffset so the element aligns with the top of the list
        return getScrollPositionDeltaToElementHelper(index, 0);
    }
}

以下是Flex 4中火花列表的简单一行:

list.layout.verticalScrollPosition = list.layout.getElementBounds(list.selectedIndex).y;
public class ScrollToElementVerticalLayout extends VerticalLayout
{   
    public override function getScrollPositionDeltaToElement(index:int):Point
    {
        // pass 0 as the topOffset so the element aligns with the top of the list
        return getScrollPositionDeltaToElementHelper(index, 0);
    }
}
list.layout.verticalScrollPosition = list.layout.getElementBounds(list.selectedIndex).y;