SwipeRefreshLayout和RecyclerView

SwipeRefreshLayout和RecyclerView

做了个项目,用了support包里的SwipeRefreshLayout和RecyclerView。两者一起使用有一点点小问题,有时候拉着拉着,列表还没拉玩就出来刷新的图标了,在华为荣耀上尤为明显。

可以这样做:

mLinearLayoutManager = new LinearLayoutManager(mActivity);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy); swipeRefreshLayout.setEnabled(mLinearLayoutManager.findFirstVisibleItemPosition() == 0);
}
});

这样就可以确保只有完全滑到顶部,然后再下拉时才刷新

04-05 21:48