[英]In Recyclerview, how to change initial scroll position to the top of first item?
[英]How in RecyclerView perform scroll item with some position to top?
我有recyclerview,它具有LinearLayoutManager,並且其中具有reverseLayout=true
。 如何將某個位置的項目滾動到屏幕頂部? 常規的recyclerView.scrollToPosition
或layoutManager.scrollToPosition
不起作用,因為以這種方式滾動的項目顯示在列表的底部和屏幕下方。
用這個 :-
linearLayoutManager!!.scrollToPositionWithOffset(0, 0)
嘗試這個
recyclerView.scrollToPosition(recyclerView.getChildCount());
要么
recyclerView.scrollToPosition(list.size());
編輯
在適配器中,您可以檢查當前位置,如果到達所需位置,則可以使用界面將recyclerView滾動到顆粒位置
recyclerView.layoutManager.scrollToPosition(0)
在你的問題,你不引用recyclerview的layoutmanager
,而是同時引用了recylcerview
和layoutmanager
逐個。
你recylcerview.layoutmanager
打電話給recylcerview.layoutmanager
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.