{"id":13642791,"url":"https://github.com/TellH/RecyclerStickyHeaderView","last_synced_at":"2025-04-20T21:31:29.516Z","repository":{"id":127060906,"uuid":"79713947","full_name":"TellH/RecyclerStickyHeaderView","owner":"TellH","description":"Sticky header view or suspending view for RecyclerView.","archived":false,"fork":false,"pushed_at":"2017-05-11T06:49:17.000Z","size":2407,"stargazers_count":345,"open_issues_count":8,"forks_count":57,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-26T20:33:21.324Z","etag":null,"topics":["android","android-library","android-ui","recyclerview"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TellH.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-01-22T11:34:14.000Z","updated_at":"2024-01-09T03:50:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"a24585c5-db59-4c90-9c6e-8d667dfaefb1","html_url":"https://github.com/TellH/RecyclerStickyHeaderView","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TellH%2FRecyclerStickyHeaderView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TellH%2FRecyclerStickyHeaderView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TellH%2FRecyclerStickyHeaderView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TellH%2FRecyclerStickyHeaderView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TellH","download_url":"https://codeload.github.com/TellH/RecyclerStickyHeaderView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223839022,"owners_count":17211859,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-library","android-ui","recyclerview"],"created_at":"2024-08-02T01:01:36.273Z","updated_at":"2025-04-20T21:31:29.509Z","avatar_url":"https://github.com/TellH.png","language":"Java","readme":"# RecyclerStickyHeaderView\n[![](https://jitpack.io/v/TellH/RecyclerStickyHeaderView.svg)](https://jitpack.io/#TellH/RecyclerStickyHeaderView)\u003cbr\u003e\nSticky header view or suspending view for RecyclerView.\u003cbr\u003e\n[StickyListHeaders](https://github.com/emilsjolander/StickyListHeaders)  is an Android library that makes it easy to integrate section headers\n stick to the top in ListView. Inspire by it, I setup this project to implement the same effect in RecyclerView.\n## Effect\n![](https://raw.githubusercontent.com/TellH/RecyclerStickyHeaderView/master/raw/effect.gif)\n\n## Usage\n\n### Setup\nroot build.gradle\n```groovy\nallprojects {\n    repositories {\n        jcenter()\n        maven { url \"https://jitpack.io\" }\n    }\n}\n```\napp build.gradle\n```groovy\ndependencies {\n   compile 'com.github.TellH:RecyclerStickyHeaderView:1.1.0'\n}\n```\n\n### Quick Start\n\n- Place RecylerView into StickyHeaderView\n``` xml\n    \u003ctellh.com.stickyheaderview_rv.StickyHeaderView\n        android:id=\"@+id/stickyHeaderView\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\u003e\n\n        \u003candroid.support.v7.widget.RecyclerView\n            android:id=\"@+id/recyclerView\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"match_parent\"\n            android:background=\"@android:color/white\"\n            android:scrollbars=\"vertical\" /\u003e\n    \u003c/tellh.com.stickyheaderview_rv.StickyHeaderView\u003e\n\n```\n\n- Create data bean class for each item type in RecyclerView. They should extend DataBean. Override the method \u003cbr\u003e\n`public boolean shouldSticky()` to decide whether the item view should be suspended on the top.\n``` java\npublic class User extends DataBean {\n    private String login;\n    private int id;\n    private String avatar_url;\n    private boolean shouldSticky;\n    @Override\n    public int getItemLayoutId(StickyHeaderViewAdapter adapter) {\n        return R.layout.item_user;\n    }\n    public void setShouldSticky(boolean shouldSticky) {\n        this.shouldSticky = shouldSticky;\n    }\n    // Decide whether the item view should be suspended on the top.\n    @Override\n    public boolean shouldSticky() {\n        return shouldSticky;\n    }\n}\npublic class ItemHeader extends DataBean {\n    private String prefix;\n    @Override\n    public int getItemLayoutId(StickyHeaderViewAdapter adapter) {\n        return R.layout.header;\n    }\n    @Override\n    public boolean shouldSticky() {\n        return true;\n    }\n}\n```\n\n- Create ViewBinder to bind different type views with specific data beans.\nAs you see, `provideViewHolder(View itemView)` corresponds for `onCreateViewHolder` in RecyclerView, and `bindView` corresponds for `onBindViewHolder` in RecyclerView.\n\n``` java\npublic class ItemHeaderViewBinder extends ViewBinder\u003cItemHeader, ItemHeaderViewBinder.ViewHolder\u003e {\n    @Override\n    public ViewHolder provideViewHolder(View itemView) {\n        return new ViewHolder(itemView);\n    }\n    @Override\n    public void bindView(StickyHeaderViewAdapter adapter, ViewHolder holder, int position, ItemHeader entity) {\n        holder.tvPrefix.setText(entity.getPrefix());\n    }\n    @Override\n    public int getItemLayoutId(StickyHeaderViewAdapter adapter) {\n        return R.layout.header;\n    }\n    static class ViewHolder extends ViewBinder.ViewHolder {\n        TextView tvPrefix;\n        public ViewHolder(View rootView) {\n            super(rootView);\n            this.tvPrefix = (TextView) rootView.findViewById(R.id.tv_prefix);\n        }\n    }\n}\n```\n\n- Instantiate StickyHeaderViewAdapter for RecyclerView and register ViewBinders for each item types.\n``` java\n        rv = (RecyclerView) findViewById(R.id.recyclerView);\n        rv.setLayoutManager(new LinearLayoutManager(this));\n        List\u003cDataBean\u003e userList = new ArrayList\u003c\u003e();\n        adapter = new StickyHeaderViewAdapter(userList)\n                .RegisterItemType(new UserItemViewBinder())\n                .RegisterItemType(new ItemHeaderViewBinder());\n        rv.setAdapter(adapter);\n```\n\nThat is all. \n\nPlease check out the Demo and source code for more information. If you have any question, feel free to raise an issue. Thanks a lot!\n\n## Thanks\n- [SuspensionBar](https://github.com/wuapnjie/SuspensionBar)\n- [NoListAdapter](https://github.com/TellH/NoListAdapter)\n\n## License\n   Copyright 2016 TellH\n   \n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n       http://www.apache.org/licenses/LICENSE-2.0\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n\n\n\n","funding_links":[],"categories":["RecyclerView"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTellH%2FRecyclerStickyHeaderView","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTellH%2FRecyclerStickyHeaderView","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTellH%2FRecyclerStickyHeaderView/lists"}