2016-12-28 82 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 –