Solve the Bug of using Android SwipeRefreshLayout & amp; RecyclerView, swiperefreshlayout

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.