All Projects → oubowu → Stickyitemdecoration

oubowu / Stickyitemdecoration

Licence: apache-2.0
强大的RecyclerView粘性头部

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Stickyitemdecoration

Consecutivescroller
ConsecutiveScrollerLayout是Android下支持多个滑动布局(RecyclerView、WebView、ScrollView等)和普通控件(TextView、ImageView、LinearLayou、自定义View等)持续连贯滑动的容器,它使所有的子View像一个整体一样连续顺畅滑动。并且支持布局吸顶功能。
Stars: ✭ 1,383 (+81.02%)
Mutual labels:  sticky-headers
Android-sticky-navigation-layout
android sticky navigation layout
Stars: ✭ 17 (-97.77%)
Mutual labels:  sticky-headers
Astickyheader
Android Sticky Headers : now headers everywhere
Stars: ✭ 390 (-48.95%)
Mutual labels:  sticky-headers
React Virtualized Sticky Tree
A React component for efficiently rendering tree like structures with support for position: sticky
Stars: ✭ 115 (-84.95%)
Mutual labels:  sticky-headers
Flutter sticky infinite list
Multi directional infinite list with Sticky headers for Flutter applications
Stars: ✭ 189 (-75.26%)
Mutual labels:  sticky-headers
StickyHeader
📐 Library helping to add a sticky header to an UIScrollView
Stars: ✭ 18 (-97.64%)
Mutual labels:  sticky-headers
Floatthead
Fixed <thead>. Doesn't need any custom css/html. Does what position:sticky can't
Stars: ✭ 1,193 (+56.15%)
Mutual labels:  sticky-headers
Azlistview
A Flutter sticky headers & index ListView. Flutter 城市列表、联系人列表,索引&悬停。
Stars: ✭ 632 (-17.28%)
Mutual labels:  sticky-headers
flutter sticky and expandable list
粘性头部与分组列表Sliver实现 Build a grouped list, which support expand/collapse section and sticky headers, support use it with sliver widget.
Stars: ✭ 116 (-84.82%)
Mutual labels:  sticky-headers
Brv
Android上最强大的RecyclerView库
Stars: ✭ 345 (-54.84%)
Mutual labels:  sticky-headers
Omegarecyclerview
Custom RecyclerView with additional functionality. Allow you add divider, itemSpace, emptyView, sticky header and some other features
Stars: ✭ 132 (-82.72%)
Mutual labels:  sticky-headers
Flutter smart select
SmartSelect allows you to easily convert your usual form select or dropdown into dynamic page, popup dialog, or sliding bottom sheet with various choices input such as radio, checkbox, switch, chips, or even custom input. Supports single and multiple choice.
Stars: ✭ 179 (-76.57%)
Mutual labels:  sticky-headers
StickyHeader
A simple lightweight sticky header ItemDecorator for RecyclerView
Stars: ✭ 108 (-85.86%)
Mutual labels:  sticky-headers
Poweradapter
Adapter for RecyclerView(only 21KB).RecyclerView万能适配器(仅21KB)
Stars: ✭ 112 (-85.34%)
Mutual labels:  sticky-headers
Flutter deer
🦌 Flutter 练习项目(包括集成测试、可访问性测试)。内含完整UI设计图,更贴近真实项目的练习。Flutter practice project. Includes a complete UI design and exercises that are closer to real projects.
Stars: ✭ 5,725 (+649.35%)
Mutual labels:  sticky-headers
Stickyheaderlistview
仿滴滴打车开具发票页,ListView粘性Header
Stars: ✭ 80 (-89.53%)
Mutual labels:  sticky-headers
react-cool-virtual
😎 ♻️ A tiny React hook for rendering large datasets like a breeze.
Stars: ✭ 1,031 (+34.95%)
Mutual labels:  sticky-headers
Scrolldir
0 dependency JS plugin to leverage scroll direction with CSS ⬆⬇ 🔌💉
Stars: ✭ 679 (-11.13%)
Mutual labels:  sticky-headers
Flutter sticky header
Flutter implementation of sticky headers for sliver
Stars: ✭ 603 (-21.07%)
Mutual labels:  sticky-headers
Flexibleadapter
Fast and versatile Adapter for RecyclerView which regroups several features into one library to considerably improve the user experience :-)
Stars: ✭ 3,482 (+355.76%)
Mutual labels:  sticky-headers

RecyclerView粘性头部

已适配Androidx,需要切到androidx分支即可

一种新的解决思路,对比我之前写的PinnedSectionItemDecoration有如下好处:

  • 粘性头部是放置在RecyclerView外面的View,对比之前绘制出来的粘性头部,能显示出点击的效果,并且处理点击事件更加简单

  • 不需要频繁的创建粘性头部的View用于绘制,只需要刷新外置的粘性头部的数据即可

效果图

普通头部 附着头部

代码实现

StickyHeadContainer用来承载粘性头部布局,并且需要和RecyclerView的顶部对齐

<RelativeLayout
    android:id="@+id/content_main"
    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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.oubowu.stickydemo.MainActivity"
    tools:showIn="@layout/activity_main">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_margin="10dp"
        tools:background="@color/colorAccent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

    </android.support.v7.widget.RecyclerView>

    <com.oubowu.stickyitemdecoration.StickyHeadContainer
        android:id="@+id/shc"
        android:layout_width="match_parent"
        android:layout_margin="10dp"
        android:layout_height="wrap_content">

        <include
            layout="@layout/item_stock_sticky_head"/>

    </com.oubowu.stickyitemdecoration.StickyHeadContainer>

</RelativeLayout>

RecyclerView只需要添加一个StickyItemDecoration即可实现粘性头部,需要传入StickyHeadContainer用于头部的处理,以及粘性头部的类型;然后头部的点击处理就像平常一样处理

        final StickyHeadContainer container = (StickyHeadContainer) findViewById(R.id.shc);
        final TextView tvStockName = (TextView) container.findViewById(R.id.tv_stock_name);
        final CheckBox checkBox = (CheckBox) container.findViewById(R.id.checkbox);
        final ImageView more = (ImageView) container.findViewById(R.id.iv_more);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mAdapter.getData().get(mStickyPosition).getData().check = isChecked;
                mAdapter.notifyItemChanged(mStickyPosition);
            }
        });
        container.setDataCallback(new StickyHeadContainer.DataCallback() {
            @Override
            public void onDataChange(int pos) {
                mStickyPosition = pos;
                StockEntity.StockInfo item = mAdapter.getData().get(pos).getData();
                tvStockName.setText(item.stickyHeadName);
                checkBox.setChecked(item.check);
            }
        });
        more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "点击了粘性头部的更多", Toast.LENGTH_SHORT).show();
            }
        });
        container.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "点击了粘性头部:" + tvStockName.getText(), Toast.LENGTH_SHORT).show();
            }
        });

        mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false));
        mRecyclerView.addItemDecoration(new StickyItemDecoration(container, RecyclerViewAdapter.TYPE_STICKY_HEAD));
        mRecyclerView.addItemDecoration(new SpaceItemDecoration(mRecyclerView.getContext()));

Adapter需要重写这两个方法,用于处理GridLayoutManager和StaggeredGridLayoutManager模式下的头部使之占满一行

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

    @Override
    public void onViewAttachedToWindow(RecyclerViewHolder holder) {
        super.onViewAttachedToWindow(holder);
        FullSpanUtil.onViewAttachedToWindow(holder, this, TYPE_STICKY_HEAD);
    }
PS:若是使用了下拉刷新的控件配合RecyclerView使用的话(显示刷新头部并且RecyclerView跟随头部的显示往下移动那种类型),因为StickyHeadContainer是独立于RecyclerView存在的,不能跟随RecyclerView移动,需要根据刷新头部的显示情况设置StickyHeadContainer的可见性

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].