It is easy to achieve jd shopping cart top function of Android library, with jd shopping cart screenshots. More articles on this library will follow. Stay tuned.


introduce

StickyHeaderForRecyclerView library’s main function is convenient RecyclerView achieve top absorption function. It currently supports the following features:

  1. Support single type top suction function
  2. Support multiple types of top suction function
  3. Enable or disable the top suction function
  4. Support the function of suction top in specified position
  5. Supports setting top offset
  6. Support custom RecyclerView Item top boundary custom
  7. It works seamlessly with AppBarLayout

The effect

  • Support single type top suction function

  • Support multiple types of top suction function

  • Enable or disable the top suction function

  • Support the function of suction top in specified position

  • Supports setting top offset

  • Support custom RecyclerView Item top boundary custom

Using the tutorial

  1. Install dependencies
  • Build. Gradle adds maven address
allprojects {
    repositories {
        jcenter()
        maven {
            url "https://dl.bintray.com/xuanyudaddy/sticky-header-recyclerview"
        }
        google()
    }
    tasks.withType(Javadoc) {
        enabled = false
    }
}
Copy the code
  • Build. Gradle add dependencies in app directory
Dependencies {implementation 'com. Xuanyu. Stickyheader: stickyheader: 1.0.0'}Copy the code
  1. Layout file added the top Layout,header. Layout for the top Layout placeholder Layout
<? The XML version = "1.0" encoding = "utf-8"? > <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler.view" android:layout_width="match_parent" android:layout_height="match_parent"></androidx.recyclerview.widget.RecyclerView> <FrameLayout android:id="@+id/header.layout" android:layout_width="match_parent" android:layout_height="wrap_content"></FrameLayout> </FrameLayout>Copy the code
  1. Create a subclass of BaseStickyHeaderModel; create a RecyclerView ItemView entity class for Book
public class BookStickyHeaderModel extends BaseStickyHeaderModel<Book> { @Override public View getStickyView(Context context) { System.out.println("jiangbin getView"); BookView bookView = new BookView(context); return bookView; } @override public void onBindView(View View, Book data) {((BookView) View).setData(new Book(data.name + "")); }}Copy the code
  1. Initialize the top code after RecyclerView#setAdapter. . You need to call StickyHeaderRegistry registerTransfer will need to suck the top Item corresponding Bean and its corresponding StickyHeaderModel one-to-one correspondence
 StickyHeaderHelper.init(mRecyclerView, mHeaderLayout, 0);
 StickyHeaderRegistry.registerTransfer(Book.class, BookStickyHeaderModel.class);
Copy the code
  1. The end! Enjoy it!!!!!

Welcome to github project address github.com/lizijin/Sti… , if you use this library, please give your valuable comments.