Skip to content
Roman Tcaregorodtcev edited this page Oct 30, 2019 · 1 revision

Sticky mode allows you to easily create sticky elements for RecyclerView using a LinearLayoutManager in either vertical or horizontal orientation.

Usage

  1. Create your own RecyclerView.Adapter class.
  2. Create "Sticky" ViewHolder.
  3. Implement StickyAdapter<T extends RecyclerView.ViewHolder>(T it's your "Sticky" ViewHolder).
  4. Override methods from StickyAdapter interface (You can look at full example here StickyHeaderAdapter.class).
public interface StickyAdapter<T extends RecyclerView.ViewHolder> {

    long getStickyId(int position);

    T onCreateStickyViewHolder(ViewGroup parent);

    void onBindStickyViewHolder(T viewHolder, int position);

}
  1. Specify stickyMode inside your xml file. Possible variants: Header, Middle. By default we use Header mode.
    <com.omega_r.libs.omegarecyclerview.OmegaRecyclerView
        android:id="@+id/recycler_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:stickyMode="Header" />

StickyHeader mode

StickyMiddle mode