NestedScrollView 内 RecyclerView 的滚动监听器?
ScrollListener for RecyclerView inside NestedScrollView?
我在 NestedScrollView
中使用 RecyclerView
。平滑滚动
nestedScrollView.setNestedScrollingEnabled(true);
recyclerView.setNestedScrollingEnabled(false);
而这个 RecyclerView
是动态的,在 scroll
上动态添加行。但是滚动侦听器不工作 NestedScrollingEnabled
是错误的。
scroller.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY > oldScrollY) {
Log.i(TAG, "Scroll DOWN");
}
if (scrollY < oldScrollY) {
Log.i(TAG, "Scroll UP");
}
if (scrollY == 0) {
Log.i(TAG, "TOP SCROLL");
}
if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
Log.i(TAG, "BOTTOM SCROLL");
f (viewGroup1.getChildAt(viewGroup1.getChildCount() - 1) instanceof RecyclerView){
//add code here }
}
}
});
我在 NestedScrollView
中使用 RecyclerView
。平滑滚动
nestedScrollView.setNestedScrollingEnabled(true);
recyclerView.setNestedScrollingEnabled(false);
而这个 RecyclerView
是动态的,在 scroll
上动态添加行。但是滚动侦听器不工作 NestedScrollingEnabled
是错误的。
scroller.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY > oldScrollY) {
Log.i(TAG, "Scroll DOWN");
}
if (scrollY < oldScrollY) {
Log.i(TAG, "Scroll UP");
}
if (scrollY == 0) {
Log.i(TAG, "TOP SCROLL");
}
if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
Log.i(TAG, "BOTTOM SCROLL");
f (viewGroup1.getChildAt(viewGroup1.getChildCount() - 1) instanceof RecyclerView){
//add code here }
}
}
});