Recyclerview pull-down refresh pull-up load (i)

Source: Internet
Author: User

ListView drop-down refresh pull-up load extension (i) http://blog.csdn.net/baiyuliang2013/article/details/50252561

ListView drop-down refresh pull-up load extension (ii)-Imitation American takeaway http://blog.csdn.net/baiyuliang2013/article/details/50253135

ListView drop-down refresh pull-up load extension (iii)-imitation of the latest version of the American group Takeaway http://blog.csdn.net/baiyuliang2013/article/details/50854592

Previous articles talked about the ListView custom pull-up loading, and recently has been considering a recyclerview drop-down refresh and pull-up loading, after all, recyclerview use more and more, Grilled on the net about Recyclerview pull-up reload loading is also a lot, but most of them can not meet like the kind of refresh effect on the ListView! For this reason, bloggers are also painstakingly thinking about two days, in the end what to do, in order to let the Recyclerview pull-up loading like a ListView 666?

We know that the ListView comes with Addheaderview and Addfooterview, is very casual to add the kinsoku layout, and in the rewriting of the ListView itself can be, but unfortunately, Recyclerview is not as convenient as the ListView to add the top and bottom layout, so the problem comes, want to achieve recyclerview pull-up and pull-up loading is bound to solve one thing is, how to give recyclerview to add the kinsoku layout?

Some students may say, Recyclerview through the adapter in the ViewType Add header and footer is not very good to do things? Yes, put aside the refresh does not say, Recyclerview Add the kinsoku layout is really convenient, but this violates the original intention of the custom view, we want to be like a ListView rewrite Recyclerview, and do not need any other conditions, to use, so this method is not OK! So what's the way, Bo Master reasoning, also by rewriting the linear layout linearlayout, order to add headerview,recyclerview,footerview the most suitable, Then listen to the linearlayout touch event to achieve the effect!

OK, after the idea, start to realize it!

* Rewrite LinearLayout, and in the constructor method, inflate out headerview,recyclerview,footerview, and add it in turn! (steps in front of several ListView refreshes similar);

* Listen to touch events, combined with several ListView processing methods, monitoring Ontouch, but sad to urge, Bo Master forget a little, now rewrite is linearlayout that is a viewgroup, Recyclerview is just a sub-view of LinearLayout, pull down when the effect is still, but do not let go on the slippery when the sad urge, Because Recyclerview and Headerview and Footerview is not like a ListView, so the effect is conceivable, so only monitoring ontouch of course is not!

Well, now we're going to have to put an event distribution mechanism ... (The event distribution mechanism, bloggers will not be fine, because bloggers are in a daze.) What do you do with me if I'm wrong? ), the previous touch event pass Graph bar:

A bit of experience with the event distribution mechanism should be easy to understand, combined with our project, then the event passing in touch Recyclerview is:

触摸RecyclerView:->LinearLayout的dispatchTouchEvent->LinearLayout的onInterceptTouchEvent->RecyclerView的dispatchTouchEvent->RecyclerView的onTouchEvent->LinearLayout的onTouchEvent

About the event distribution mechanism do not know students can self-Baidu, pay attention to a little, the minimum view is no onintercepttouchevent interception event!

Well, the event was distributed good grasp, down to the chant! But as the saying goes, do not reinvent the wheel, hehe, so Bo Master also refer to the open source Pulltorefresh part of the code (of course, everyone in the use of the wheel must understand the principle, to achieve extrapolate effect, not to pursue the confused take doctrine), Combined with the Recyclerview in this project, pull-down refreshes and pull-up loads like a ListView are completed!

Let's look at the results:

Layout code:

<?xml version= "1.0" encoding= "Utf-8"?><relativelayout  xmlns: Android  = "http://schemas.android.com/apk/res/android"  android:layout_width  =" match_parent " android:layout_height  =;         <com.byl.recyclerview.view.PullRecyclerViewandroid:id="@+id/recyclerview" android:layout_width="Match_parent"android:layout_height="Match_parent" android:orientation="vertical"/>                                                </relativelayout>

Implementation code:

   recyclerView = (PullRecyclerView) findViewById(R.id.recyclerView);        recyclerView.setOnHeaderRefreshListener(this);        recyclerView.setOnFooterRefreshListener(this);        recyclerView.setLayoutManager(new LinearLayoutManager(this));        myAdapter = new MyAdapter();        recyclerView.setAdapter(myAdapter);

In this case, there is no way to disable pull-up, you can set a method according to your needs, in the touch event to judge! You can disable pull-up loading when the item number is not one screen!

asdemo:http://download.csdn.net/detail/baiyuliang2013/9531776

Recyclerview Pull-up reload (i)

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.