android - RecyclerView LinearLayoutManager.scrollToPositionWithOffset 不起作用

标签 android android-recyclerview

我想将RecyclerView滚动到某个位置,我使用LinearLayoutManager.scrollToPositionWithOffset()来滚动,但它不起作用。有人可以帮助我吗?

我的代码:

初始化RecyclerView:

mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

Button onClick中,我这样做是为了滚动View:

((LinearLayoutManager)mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(position, offset);

最佳答案

我认为你应该使用RecyclerView.smoothScrollToPosition(position),其中position是你当前的位置+偏移量。

关于android - RecyclerView LinearLayoutManager.scrollToPositionWithOffset 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31265476/

相关文章:

android - 在android中慢慢填充颜色的圆圈

java - RecyclerView 滚动时困惑

android - 无法在我的 Android 库项目中使用 RecyclerView

android - 刷新后我会得到 C2DM 注册 ID 吗?

java - 数据未绑定(bind)到 recyclerview

android - fragment 中的 RecyclerView 不工作(无法向其添加数据)

java - 我有一个回收器 View ,onRun 将显示,但单击按钮后它将为空,我想设置默认回收器 View

java - 如何在 Java 中使用静态抽象类作为回调?

android - 如何获取OkHttp 4.x的UserAgent?

android "squishing"游戏画面进入大屏左上角