1. 程式人生 > >SwipeRefreshLayout和RecyclerView同時使用出現RecyclerView的item被裁剪

SwipeRefreshLayout和RecyclerView同時使用出現RecyclerView的item被裁剪

用Android提供的support包裡的SwipeRefreshLayout和RecyclerView同時使用的時候會出現RecyclerView的item被裁剪的情況,如下圖所示:

在這裡插入圖片描述

解決此Bug的方法
參考資料如下:

http://stackoverflow.com/questions/25178329/recyclerview-and-swiperefreshlayout/25227797#25227797

https://gist.github.com/VladSumtsov/ad4e13511a9b73ff3b13

上面顯示的是兩種解決辦法,我推薦第二種比較簡單,我的程式碼片段如下:

mLayoutManager = new LinearLayoutManager(getActivity());
			//mPicListView是RecyclerView物件
			mPicListView.setLayoutManager(mLayoutManager);
			mPicListView.setOnScrollListener(new OnScrollListener() {
				@Override
				public void onScrollStateChanged(RecyclerView recyclerView,
						int newState) {
super.onScrollStateChanged(recyclerView, newState); //載入更多 if (!isLoading && hasMore && mAdapter.getItemCount() == (mLayoutManager .findLastVisibleItemPosition() + 1) && newState == RecyclerView.SCROLL_STATE_IDLE) { isLoading =
true; requestServerArticleMore(); } } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); //解決RecyclerView和SwipeRefreshLayout共用存在的bug mRefreshLayout.setEnabled(mLayoutManager .findFirstCompletelyVisibleItemPosition() == 0); } });

轉載自:https://blog.csdn.net/zhangweiwtmdbf/article/details/41206369