解決卡頓的方法最簡單的就是設定RecyclerView的android:nestedScrollingEnabled="false",放棄自己的滑動,交給外部的NestedScrollView處理,就沒有出現卡頓的現象了
至于RecyclerView的上拉重新整理,可以監聽NestedScrollView的滑動監聽,具體代碼如下:
mNestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY > oldScrollY) {
// 向下滑動
}
if (scrollY < oldScrollY) {
// 向上滑動
}
if (scrollY == 0) {
// 頂部
}
if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
// 上拉重新整理實作
}
}
});