https://github.com/takwolf/android-headerandfooterrecyclerview
Let RecyclerView support add header and footer views
https://github.com/takwolf/android-headerandfooterrecyclerview
android footerview headerview recyclerview
Last synced: about 1 year ago
JSON representation
Let RecyclerView support add header and footer views
- Host: GitHub
- URL: https://github.com/takwolf/android-headerandfooterrecyclerview
- Owner: TakWolf
- License: apache-2.0
- Created: 2017-05-30T22:36:08.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2025-03-22T20:24:06.000Z (over 1 year ago)
- Last Synced: 2025-03-22T21:31:24.562Z (over 1 year ago)
- Topics: android, footerview, headerview, recyclerview
- Language: Java
- Homepage:
- Size: 595 KB
- Stars: 42
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Android - HeaderAndFooterRecyclerView
[](https://developer.android.com)
[](https://android-arsenal.com/api?level=21)
[](https://www.apache.org/licenses/LICENSE-2.0)
[](https://jitpack.io/#TakWolf/Android-HeaderAndFooterRecyclerView)
`RecyclerView` 添加 `HeaderView` 和 `FooterView` 的解决方案。
拥有如下特性:
- 对业务 `Adapter` 无侵入,也不需要额外的包装 `Adapter`。
- `HeaderView` 和 `FooterView` 直接挂载在 `RecyclerView` 上,无需手动处理重用问题。
- 支持 `LinearLayoutManager`、`GridLayoutManager` 和 `StaggeredGridLayoutManager` 三种布局管理器的横向和纵向布局。
- 支持多个 `HeaderView` 和 `FooterView`,并且可以动态添加和删除。
- 支持动态切换 `Adapter` 和 `LayoutManager`。
- 额外提供分页组件,方便快速实现「下拉刷新」和「加载更多」功能。
## Usage
```kotlin
repositories {
maven { setUrl("https://jitpack.io") }
}
dependencies {
implementation("androidx.core:core-ktx:1.15.0")
implementation("androidx.recyclerview:recyclerview:1.4.0")
implementation("com.github.TakWolf.Android-HeaderAndFooterRecyclerView:hfrecyclerview:0.0.18")
// 可选。分页组件。
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.1")
implementation("androidx.lifecycle:lifecycle-common:2.8.7")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
implementation("com.github.TakWolf.Android-HeaderAndFooterRecyclerView:paging:0.0.18")
}
```
```xml
```
```kotlin
val recyclerView = findViewById(R.id.recycler_view)
recyclerView.layoutManager = LinearLayoutManager(context)
recyclerView.adapter = adapter
val headerView = layoutInflater.inflate(R.layout.header, recyclerView.headerViewContainer, false)
recyclerView.addHeaderView(headerView)
val footerView = layoutInflater.inflate(R.layout.footer, recyclerView.footerViewContainer, false)
recyclerView.addFooterView(footerView)
```
## License
```
Copyright 2022 TakWolf
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.
```