简体   繁体   English

如何在RecyclerView中执行从顶部到某个位置的滚动项目?

[英]How in RecyclerView perform scroll item with some position to top?

I have recyclerview, that have LinearLayoutManager and in it reverseLayout=true . 我有recyclerview,它具有LinearLayoutManager,并且其中具有reverseLayout=true How can I scroll item with some position to the top of the screen? 如何将某个位置的项目滚动到屏幕顶部? Regular recyclerView.scrollToPosition or layoutManager.scrollToPosition didn't work, because item scrolled by that way displayed at the bottom of list and under the screen. 常规的recyclerView.scrollToPositionlayoutManager.scrollToPosition不起作用,因为以这种方式滚动的项目显示在列表的底部和屏幕下方。

用这个 :-

linearLayoutManager!!.scrollToPositionWithOffset(0, 0)

try this 尝试这个

recyclerView.scrollToPosition(recyclerView.getChildCount());

or 要么

recyclerView.scrollToPosition(list.size());

Edit 编辑

in your adapter you can check your current position, if you reach desired position you can scroll recyclerView to particulate position using interface 在适配器中,您可以检查当前位置,如果到达所需位置,则可以使用界面将recyclerView滚动到颗粒位置

recyclerView.layoutManager.scrollToPosition(0)

In your question you don't reference the recyclerview's layoutmanager but instead reference both the recylcerview and layoutmanager individually. 在你的问题,你不引用recyclerview的layoutmanager ,而是同时引用了recylcerviewlayoutmanager逐个。

You much call recylcerview.layoutmanager recylcerview.layoutmanager打电话给recylcerview.layoutmanager

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM