It’s been a year since my last post, and this time I’m bringing you SmartRefreshHorizontal, another open source library. First look at the results:

portal

  • The project address
  • Properties of the document
  • Q&A
  • Update log
  • Download the source code
  • The custom Header

Demo

Download the APK – Demo

Results demonstrate

Goods details ViewPager
Data presentation

origin

SmartRefreshLayout’s design is flexible and scalable, which I think is one of the reasons for its popularity. A number of people in the issue area have suggested that SmartRefreshLayout support landscape refresh. In fact, everyone knows that there are already several horizontal refresh libraries, and my response to them is to use other existing horizontal refresh libraries. But this has caused a lot of discussion in issue, probably because the use, functionality, and extensions of the horizontal refresh library are quite different from SmartRefreshLayout. So I think the horizontal refresh library needs to be as versatile and extensible as SmartRefreshLayout. Extending SmartRefreshLayout to support landscape directly would increase the amount of code. By this time, however, it was big enough, and there were complaints that it was too big and needed subcontracting refinement. So I had little intention of developing a horizontal refresh feature at first. Because landscape refresh is used in far fewer application scenarios than vertical refresh, I rarely use it myself. If it’s not worth the time and effort to implement a library of features that I don’t use very often, it’s not worth it to implement a simple landscape refresh…

The principle of

Finally! One day while developing rotation animations, I had a wonderful idea: what if I rotated SmartRefreshLayout 90 degrees? Then experiment: Rotate SmartRefreshLayout 90 degrees and Content -90 degrees. Turns out it actually works!! So I don’t have to spend a lot of time and energy to do horizontal refresh code implementation, SmartRefreshLayout all the original functions can be used directly, before the design of more than ten headers and Footer can be used directly without any modification! This gave me the motivation to develop a horizontal refresh library. The SmartRefreshHorizontal library was born out of this experimental idea!

SmartRefreshLayout, as an extension library of SmartRefreshLayout, implements horizontal refresh and loading functions. Although it is an independent open source library, it does not repeat the implementation, but encapsulates and transforms SmartRefreshLayout. Make it support horizontal refresh. So SmartRefreshHorizontal inherits all of SmartRefreshLayout’s features, but with a horizontal orientation.

SmartRefreshHorizontal and SmartRefreshLayout, then you should rely on SmartRefreshLayout when using this library, and the version should be greater than 1.1.0, otherwise you will find the error of not finding the class.

Simple use case

1. Add dependencies in build.gradle

    implementation 'com. Scwang. Smartrefresh: SmartRefreshHorizontal: 1.0.0 - beta - 1'
    implementation 'com. Scwang. Smartrefresh: SmartRefreshLayout: 1.1.0'// Must rely on version 1.1.0 or later

    //androidx
    implementation 'com. Scwang. Smartrefresh: SmartRefreshHorizontal: 1.0.0 andx - 1'
    implementation 'com. Scwang. Smartrefresh: SmartRefreshLayout: 1.1.0 - andx - 16'// Must rely on version 1.0-ANDX-16 and above
Copy the code

2. Add SmartRefreshHorizontal to the XML layout file

<?xml version="1.0" encoding="utf-8"? >
<com.scwang.smartrefresh.horizontal.SmartRefreshHorizontal xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/refreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:overScrollMode="never"
        android:orientation="horizontal"
        android:background="#fff" />
</com.scwang.smartrefresh.horizontal.SmartRefreshHorizontal>
Copy the code

3. Add code to your Activity or Fragment

   RefreshLayout refreshLayout = root.findViewById(R.id.refreshLayout);
   refreshLayout.setRefreshHeader(new MaterialHeader(root.getContext()));
   refreshLayout.setRefreshFooter(new RefreshFooterWrapper(new MaterialHeader(root.getContext())), -1, -2);
Copy the code

confusion

SmartRefreshHorizontal does not need to add obturation filtering code and has passed the obturation test. Please let me know if you have any problems after obturation during the use of the project.