Solve the Bug of using Android SwipeRefreshLayout & RecyclerView, swiperefreshlayout
1. Introduction
When using SwipeRefreshLayout and RecyclerView in the support package provided by Android, the item of RecyclerView is cropped, as shown in:
2. solution to this Bug
The references are as follows:
Http://stackoverflow.com/questions/25178329/recyclerview-and-swiperefreshlayout/25227797#25227797
Https://gist.github.com/VladSumtsov/ad4e13511a9b73ff3b13
The above shows two solutions. I recommend the second method to be simple. My code snippets are as follows:
MLayoutManager = new LinearLayoutManager (getActivity (); // mPicListView is the RecyclerView object mPicListView. setLayoutManager (mLayoutManager); mPicListView. setOnScrollListener (new OnScrollListener () {@ Overridepublic void onScrollStateChanged (RecyclerView recyclerView, int newState) {super. onScrollStateChanged (recyclerView, newState); // load more if (! IsLoading & hasMore & mAdapter. getItemCount () = (mLayoutManager. findLastVisibleItemPosition () + 1) & newState = RecyclerView. SCROLL_STATE_IDLE) {isLoading = true; requestServerArticleMore () ;}@overridepublic void onScrolled (RecyclerView recyclerView, int dx, int dy) {super. onScrolled (recyclerView, dx, dy); // solves the problem that the RecyclerView and SwipeRefreshLayout share the existing bugmRefreshLayout. setEnabled (mLayoutManager. findFirstCompletelyVisibleItemPosition () = 0 );}});
Hope to help you.