Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

PinnedSectionItemDecoration

> 编程语言
Open source

A powerful ItemDecoration for Recyclerview, supports the common layoutmanager.

2.1K stars0 likes0 views
WebsiteGitHub

About

A powerful ItemDecoration for Recyclerview, supports the common layoutmanager.

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

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:

groovy
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」

…

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

…

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

…

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」

…

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.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javarecyclerviewstickyheader

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言