【问题标题】:RadListView - scroll to a specific y-positionRadListView - 滚动到特定的 y 位置
【发布时间】:2016-12-28 15:31:42
【问题描述】:

在 RadListView 中,是否可以滚动到特定的 y 位置。

问题是如果我从 RadListView 页面导航到另一个页面然后返回 - 它会初始化到列表视图的顶部。在导航到另一个页面之前,我希望用户处于相同的 y 位置。

我认为有一种滚动到项目的方法 - 但这不一定是相同的 y 位置。

【问题讨论】:

    标签: nativescript radlistview


    【解决方案1】:

    您可以使用可观察的 ViewModel 缓存您的索引,并在需要时传递它(在这种情况下,在您的列表的 loaded 事件上 - 即用户将返回的时间到列表页面,列表将加载)

    例如打字稿

    page.ts

    export function onListLoaded(args: RadListwModule.ListViewEventData) {
        list = <RadListwModule.RadListView>args.object;
    
        if (list.items) {
            list.scrollToIndex(roversViewModel.get("cachedIndex"));
        }
    
        list.refresh();
    }
    
    export function onItemTap(args: RadListwModule.ListViewEventData) {
        var tappedItemIndex = args.itemIndex;
    
        // "cache" the index of our tapped  item
        roversViewModel.set("cachedIndex", tappedItemIndex);
    
        // navigate to  details page or do what you want to do on itemTap
        frame.topmost().navigate(navEntry);
    }
    

    page.xml

     <lv:RadListView items="{{ dataItems }}" loaded="onListLoaded" itemTap="onItemTap">
    

    第一次加载列表时,还要给你的 cachedIndex initial value of 0

    基于this POC app 的示例。 请注意,这与 scroll-to-the-exact-y-position 并不完全相同,但您可以修改逻辑并通过获取单元格相对位置偏移量进一步滚动到确切位置。

    【讨论】:

    • 感谢您的解决方案。我发现 scrollToIndex() 方法使项目可见 - 可能位于屏幕的顶部、中间或底部。那么 - 我如何获得单元格的相对位置偏移量。似乎有一个 scrollToPosition() 方法 - 也许这就是解决方案?
    • 好吧,此时 scrollPosition 属性仅适用于 iOS 的 RadListView docs.telerik.com/devtools/nativescript-ui/Controls/NativeScript/… .. 除此之外,还有一个非常好的方法,称为 getLocationRelativeTo(),适用于任何视图
    猜你喜欢
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 2018-02-23
    • 2015-10-11
    • 2011-10-03
    相关资源
    最近更新 更多