2016-12-28 83 views
0

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

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

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

回答

0

可以使用可观察到的视图模型缓存索引并在需要时通过它(在这种情况下,在加载事件列表 - 即当用户将返回到列表页和列表将加载)

例如打字稿

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-exact-y-position不完全相同,但您可以修改逻辑并通过获取单元格相对位置偏移进一步滚动到确切位置。

+0

感谢您的解决方案。我发现scrollToIndex()方法使项目可见 - 可以位于屏幕的顶部,中部或底部。所以 - 我如何获得细胞的相对位置偏移。似乎有一个scrollToPosition()方法 - 也许这是解决方案? – dashman

+0

那么在这个时刻scrollPosition属性仅适用于iOS的RadListView http://docs.telerik.com/devtools/nativescript-ui/Controls/NativeScript/ListView/How-To/scroll-to-index#changing-the -position-of-the-scroll-to-item-ios-only ..除此之外,还有一个非常好的方法,称为getLocationRelativeTo(),它适用于任何View –