【发布时间】:2016-11-05 21:33:48
【问题描述】:
我想用recyclerView 实现分页,为此我将addOnScrollListener 添加到recyclerView,但是当我设置rvGridExplore.setNestedScrollingEnabled(false); 时,RecyclerView.OnScrollListener 无法正常工作
但是当我删除 rvGridExplore.setNestedScrollingEnabled(false); 它工作正常,
我不知道如何处理。
代码如下:
rvGridExplore = (RecyclerView) view.findViewById(R.id.rvGridExplore);
final GridLayoutManager glm = new GridLayoutManager(context,2);
// rvGridExplore.setNestedScrollingEnabled(false);
rvGridExplore.setLayoutManager(glm);
// final int visibleItemCount,totalCount,pastVisibleItems;
rvGridExplore.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
Log.v("scrollll","state changed");
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0) {
int totalCount = glm.getItemCount();
int visibleItemCount = glm.getChildCount();
int pastVisibleItems = glm.findFirstVisibleItemPosition();
if (loading) {
if ((visibleItemCount + pastVisibleItems) >= totalCount) {
Log.v("scroll","scrolled"+pastVisibleItems);
}
}
}
}
});
【问题讨论】:
-
为什么需要调用 setNestedScrollingEnabled(false)?
-
它位于协调器布局下的 NestedScrollView 下,如果我删除它,工具栏不会向上滚动
-
等等,你想让工具栏向上滚动还是不向上滚动?
-
我想向上滚动,当 rvGridExplore.setNestedScrollingEnabled(false); 时找到它的工作;
-
这没有意义……应该是相反的。
标签: android android-recyclerview android-nestedscrollview