将数据加载到适配器时遇到 UI 问题。列表项包含通过 Glide 库加载的类似聊天的对象、文本和图像,有时 RecyclerView 位置不正确,它会滚动到上方一点(使用 app:reverseLayout="true")。
当消息不包含图像时,它会很好地呈现并滚动到底部。但看起来加载图像会弄乱滚动位置,我尝试过不同的插件,但我认为这不是问题。
有人遇到过类似的问题吗?我已经在观察加载状态,当它没有加载滚动到 0 位置(片段)时,但看起来在布局完成绘制之前完成,并且它向下滚动,但在 300-400 毫秒(有时多一点)之后,它滚动到第 3/4 个列表项的位置。
片段:
adapter.loadStateFlow
// Only emit when REFRESH LoadState for RemoteMediator changes.
.distinctUntilChangedBy { it.refresh }
// Only react to cases where REFRESH completes, such as NotLoading.
.filter { it.refresh is LoadState.NotLoading }
// Scroll to top is synchronous with UI updates, even if remote load was
// triggered.
.collect { binding.recyclerView.scrollToPosition(0) }
此外,设置延迟也没有帮助。
我正在使用 RecyclerView 和 PagingDataAdapter/Paging3。