android - NestedScrollView 内的 RecyclerView 在 NotifyDataSetChanged 后继续滚动 - 问题
问题描述
我在 NestedScrollView 中添加了 RecyclerView。在第一次尝试从服务器获取数据并在 UI 上呈现时,还添加了滚动侦听器。这对我来说很好。
问题是当我滚动到 NestedScrollView 的底部时,另一个服务器调用以获取更多数据,将数据添加到列表后,我调用了 notifydataSetchanged。但是这次刷新数据后 NestedScrollView 继续自动滚动。
看起来像:
1)最后滚动到底部首先暂停
2)在服务器 API 调用后刷新列表
3)暂停的滚动,现在自动恢复。
这是我的滚动监听器:
nested_scroll_layout.getViewTreeObserver().addOnScrollChangedListener(new
ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
View view =
nested_scroll_layout.getChildAt(nested_scroll_layout.getChildCount() - 1);
int diff = (view.getBottom() - (nested_scroll_layout.getHeight()
+ nested_scroll_layout
.getScrollY()));
if (diff == 0 && !isCommentaryLoading) {
isCommentaryLoading = true;
hitCommentryApi(true);
}
}
});
=======================================
API 响应成功后,将数据添加到当前列表中。
then `commentaryAdapter.notifyDataSetChanged();`
解决方案
推荐阅读
- ios - 使用相同的请求标识符同时注册 2 个本地通知不被覆盖
- javascript - 无法在 Dialogflow 中存储下一轮对话的变量列表
- ios - tableView reloadData 不起作用,委托方法
- python - Pandoc 转换字典
- jena - 从 Jena 编写嵌入 JSON-LD
- google-apps-script - Google Scripts HtmlService 返回未定义的表单数据
- gnuplot - Gnuplot 和数据差距
- c - 如何使用 libgit2 中的 mempack?
- azure-machine-learning-studio - 在调用 Azure 机器学习函数时在 Azure 流分析中出现错误请求结果,即使从 C# 调用 Azure ML 服务也很好
- linux - 根本无法让 Crontab 工作正常工作