(Smooth)ScrollToPosition 不能与 RecyclerView 一起正常工作

编程入门 行业动态 更新时间:2024-10-10 08:18:45
本文介绍了(Smooth)ScrollToPosition 不能与 RecyclerView 一起正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用带有 GridLayoutManager 的基本 RecyclerView.我观察到 smoothScrollToPosition 和 scrollToPosition 都不能正常工作.

I'm using basic RecyclerView with GridLayoutManager. I observed that nor smoothScrollToPosition nor scrollToPosition works properly.

a) 使用 smoothScrollToPosition 时,我经常收到来自 RecyclerView

a) when using smoothScrollToPosition I often receive error from RecyclerView

RecyclerView:平滑滚动时越过目标位置."

"RecyclerView﹕ Passed over target position while smooth scrolling."

和 RecyclerView 未正确滚动(通常会错过目标行).这主要是在我尝试滚动到某行的第一项时观察到的

and RecyclerView is not scrolled properly (often it misses the targeted row). This is observed mostly when I'm trying to scroll to the 1st item of some row

b) 当使用 scrollToPosition 时,它似乎工作得很好,但大多数时候我只能看到该行的第 1 项,其余的都没有显示.

b) when using scrollToPosition it seems to work quite ok but most of the time I can see only the 1st item of the row and the rest are not displayed.

你能给我一些提示如何使至少一种方法正常工作吗?

Can you give me some hints how to make work properly at least one of the methods?

非常感谢!

推荐答案

我终于能够让它工作了!LinearLayoutManager.scrollToPositionWithOffset(int, int) 成功了.

Finally I was able to make it work! LinearLayoutManager.scrollToPositionWithOffset(int, int) did the trick.

更多推荐

(Smooth)ScrollToPosition 不能与 RecyclerView 一起正常工作

本文发布于:2023-10-30 18:50:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1543697.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:能与   工作   Smooth   ScrollToPosition   RecyclerView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!