All Projects → oubowu → Pinnedsectionitemdecoration

oubowu / Pinnedsectionitemdecoration

Licence: apache-2.0
A powerful ItemDecoration for Recyclerview, supports the common layoutmanager.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Pinnedsectionitemdecoration

PinnedSectionRecyclerView
simple RecyclerView with pinned sections for Android.
Stars: ✭ 21 (-98.96%)
Mutual labels:  recyclerview, stickyheader
Notzz App
📝 A Simple Note-Taking App built to demonstrate the use of Modern Android development tools - (Kotlin, Coroutines, State Flow, Hilt-Dependency Injection, Jetpack DataStore, Architecture Components, MVVM, Room, Material Design Components).
Stars: ✭ 158 (-92.21%)
Mutual labels:  recyclerview
Omegarecyclerview
Custom RecyclerView with additional functionality. Allow you add divider, itemSpace, emptyView, sticky header and some other features
Stars: ✭ 132 (-93.49%)
Mutual labels:  recyclerview
Android Rv Swipe Delete
RecyclerView swipe to delete example.
Stars: ✭ 143 (-92.95%)
Mutual labels:  recyclerview
Simplerecyclerview
Android RecyclerView 简化使用: 下拉刷新, 加载更多, 加载中/空数据/错误页面, 固定Header, 分割线, 点击监听, Item 动画, 分组显示 Title. (Android RecyclerView easy-to-use: Pull-To-Refresh, load more, Loading/Empty/Error View, sticky headers, divider, click listener, item animation, group display.)
Stars: ✭ 134 (-93.39%)
Mutual labels:  recyclerview
Android List To Grid
Implementation of List to Grid: Icon Transition
Stars: ✭ 147 (-92.75%)
Mutual labels:  recyclerview
Easyrecyclerview
🎞 Easy recyclerview for Android
Stars: ✭ 131 (-93.54%)
Mutual labels:  recyclerview
Android Collectiondemo
集合了多个框架编译的demo,GreenDao数据库、网络访问、recyclerview、Lottie动画等
Stars: ✭ 166 (-91.81%)
Mutual labels:  recyclerview
Hfrecyclerview
Add Header and/or Footer in your RecyclerView in the simplest way possible.
Stars: ✭ 157 (-92.25%)
Mutual labels:  recyclerview
Recyclerviewadapter
A RecyclerView Adapter that support load more and add headerview
Stars: ✭ 141 (-93.04%)
Mutual labels:  recyclerview
Expandablerecyclerview
ExpandableRecyclerView with smoothly animation.
Stars: ✭ 135 (-93.34%)
Mutual labels:  recyclerview
Tableview
A RecyclerView that looks like a TableView, can scroll horizontally and vertically with a fixed header at the same time.
Stars: ✭ 135 (-93.34%)
Mutual labels:  recyclerview
Customtvrecyclerview
Stars: ✭ 154 (-92.4%)
Mutual labels:  recyclerview
Coinverse
Coinverse Open App is the first audiocast app for cryptocurrency news. 🚀
Stars: ✭ 133 (-93.44%)
Mutual labels:  recyclerview
Easyadapter
Android 轻量级适配器,简化使用,适应所有的AbsListView、RecyclerView。支持HeaderView与FooterView~
Stars: ✭ 160 (-92.11%)
Mutual labels:  recyclerview
Kotlin Adapter
🔥 RecyclerView,AbsListView适配器, 支持多种视图样式, 支持吸顶、侧滑删除、拖拽效果
Stars: ✭ 132 (-93.49%)
Mutual labels:  recyclerview
Cardstackview
📱Tinder like swipeable card view for Android
Stars: ✭ 1,850 (-8.73%)
Mutual labels:  recyclerview
Drag Select Recyclerview
👇 Easy Google Photos style multi-selection for RecyclerViews, powered by Kotlin and AndroidX.
Stars: ✭ 1,818 (-10.31%)
Mutual labels:  recyclerview
Timeline
瀑布流式的时间轴
Stars: ✭ 2,028 (+0.05%)
Mutual labels:  recyclerview
Materialtransitionanimation
Material Animations practice which is inspired from
Stars: ✭ 165 (-91.86%)
Mutual labels:  recyclerview

Pinned section header decoration for RecyclerView.

中文版文档点这里

(Please pay attention to a better project StickyItemDecoration)

A powerful pinned section header library. The realization of ideas comes from「pinned-section-item-decoration」. Please mark a star if you think it's helpful.(^∀^)

Function

  • Large pinned section header support vertical orientation of the LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager.
  • Small pinned section header support vertical orientation of the LinearLayoutManager and GridLayoutManager which its span count is 1.
  • Support the header of the click, double click and long press event.
  • Support the child view of the click, double click and long press event.
  • It can draw the separator line and support custom separator line style. (PS: Vertical staggeredgrid layout requires fixed height, can not be randomly changed to lead to item position switch, refer to「See line 89-108 of MainActivity」)

Screenshot

大标签线性布局 大标签网格布局 大标签瀑布流布局 小标签线性布局 股市Demo

Extension library

BaseRecyclerViewAdapterHelper(It is highly recommended to use this adapter, which can greatly reduce the amount of work. The current demo is using v2.9.42.)

How to use?

To add a dependency using Gradle:

If using androidx
    compile 'com.oushangfeng:PinnedSectionItemDecoration:1.3.2-androidx'
otherwise
    compile 'com.oushangfeng:PinnedSectionItemDecoration:1.3.2'

Adapter needs to process the span count of header through the FullSpanUtil.

    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        FullSpanUtil.onAttachedToRecyclerView(recyclerView, this, StockEntity.StockInfo.TYPE_HEADER);
    }

    @Override
    public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
        super.onViewAttachedToWindow(holder);
        FullSpanUtil.onViewAttachedToWindow(holder, this, StockEntity.StockInfo.TYPE_HEADER);
    }

To achieve large pinned section header, RecyclerView only need to add a PinnedHeaderItemDecoration. Note that the top layer of the header where the layout can not be set marginTop.「See StockActivity

      OnHeaderClickAdapter clickAdapter = new OnHeaderClickAdapter() {

          @Override
          public void onHeaderClick(View view, int id, int position) {
              switch (id) {
                  case R.id.fl:
                       // case OnItemTouchListener.HEADER_ID:
                       Toast.makeText(StockActivity.this, "click, tag: " + mAdapter.getData().get(position).pinnedHeaderName, Toast.LENGTH_SHORT).show();
                       break;
                   case R.id.iv_more:
                       Toast.makeText(StockActivity.this, "click " + mAdapter.getData().get(position).pinnedHeaderName + "'s more button", Toast.LENGTH_SHORT)
                             .show();
                       break;
                   case R.id.checkbox:
                       final CheckBox checkBox = (CheckBox) view;
                       checkBox.setChecked(!checkBox.isChecked());
                       // invalidate ItemDecorations to draw the header
                       mRecyclerView.invalidateItemDecorations();

                       mAdapter.getData().get(position).check = checkBox.isChecked();
                       mAdapter.notifyItemChanged(position + mHeaderItemDecoration.getDataPositionOffset());

                       break;
               }
           }

       };

     mRecyclerView.addItemDecoration(
             // Set the type of pinned header
             new PinnedHeaderItemDecoration.Builder(StockEntity.StockInfo.TYPE_HEADER)
             // Set separator line resources id.
             .setDividerId(R.drawable.divider)
             // Enable draw the separator line, by default it's disable.
             .enableDivider(true)
             // Set click event for the header and its internal child view.
             .setClickIds(R.id.iv_more)
             // Disable header click event, by default it's enable.
             .disableHeaderClick(false)
             // Set the listener. If the listener is not null but disable the header click event(eg. disableHeaderClick(true)), then the callback don't return.
             .setHeaderClickListener(clickAdapter)
             .create());
    

大标签布局

To achieve small pinned section header is a little bit more complex, such as the layout A of the data .

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:background="#70E593">

    <ImageView
        android:id="@+id/iv_animal"
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        tools:src="@mipmap/panda0"/>

    <TextView
        android:id="@+id/tv_pos"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="8dp"
        android:textColor="#000000"
        android:textSize="18dp"
        tools:text="1"/>

</FrameLayout>

布局A

This is a layout B with a small pinned section header.

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/iv_animal"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:background="#70E593"
        tools:src="@mipmap/panda0"/>

    <ImageView
        android:id="@+id/iv_small_pinned_header"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#5A5A5A"
        android:padding="8dp"
        android:textColor="#ffffff"
        android:textSize="18dp"
        tools:src="@mipmap/panda0"
        tools:text="熊猫"/>

</FrameLayout>

布局B

The layout B add a header compare whit layout A,then RecyclerView only need to add a SmallPinnedHeaderItemDecoration. Note that the top layer of the header where the layout can not be set marginTop.「See SecondActivity

     OnHeaderClickAdapter headerClickAdapter = new OnHeaderClickAdapter() {

          @Override
          public void onHeaderClick(View view, int id, int position) {
              if (id == R.id.iv_small_pinned_header) {
                  Toast.makeText(SecondActivity.this, "click tag: " + mAdapter.getData().get(position).getPinnedHeaderName(), Toast.LENGTH_SHORT).show();
              }
          }
     };
     mRecyclerView.addItemDecoration(
             // Constructor need to set the id and type of the header 
             new SmallPinnedHeaderItemDecoration.Builder(R.id.tv_small_pinned_header,BaseHeaderAdapter.TYPE_HEADER)
             // Enable draw the separator line, by default it's disable.
             .enableDivider(true)
             // Set separator line resources id.
             .setDividerId(R.drawable.divider)
             // Set click event for the header and its internal child view.
             .setClickIds(R.id.tv_small_pinned_header)
             // Disable header click event, by default it's enable.
             .disableHeaderClick(false)
             // Set the listener. If the listener is not null but disable the header click event(eg. disableHeaderClick(true)), then the callback don't return.
             .setHeaderClickListener(clickAdapter)
             .create());
    

License

Copyright 2016 oubowu

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].