All Projects → TakWolf → Android-HeaderAndFooterRecyclerView

TakWolf / Android-HeaderAndFooterRecyclerView

Licence: Apache-2.0 license
Let RecyclerView support add HeaderView and FooterView.

Programming Languages

kotlin
9241 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Android-HeaderAndFooterRecyclerView

Swiperecyclerview
🍈 RecyclerView侧滑菜单,Item拖拽,滑动删除Item,自动加载更多,HeaderView,FooterView,Item分组黏贴。
Stars: ✭ 5,174 (+14272.22%)
Mutual labels:  recyclerview, footerview, headerview
Lrecyclerview
RecyclerView下拉刷新,自动加载更多;仿IOS侧滑Item删除菜单(盼望大家扩展更多功能)
Stars: ✭ 2,466 (+6750%)
Mutual labels:  recyclerview, footerview, headerview
SmartStickyHeader
A Custom Header View With Multiple Items to make selection from categories
Stars: ✭ 36 (+0%)
Mutual labels:  recyclerview, headerview
MetalRecyclerPagerView
RecyclerView implementation for Android which makes it look and feel like ViewPager with item margins support (mutliple views effect).
Stars: ✭ 26 (-27.78%)
Mutual labels:  recyclerview
HoveringCallback
Drag & drop item decorator for RecyclerView with support for highlighting hovered items.
Stars: ✭ 15 (-58.33%)
Mutual labels:  recyclerview
swipeablerecyclerview
SwipeableRecyclerView provides a wrapper class SwipeItemTouchHelperCallback which can be used to add Dragging capability to your RecyclerView items. You can make use of DataBinding to bind it via XML.
Stars: ✭ 16 (-55.56%)
Mutual labels:  recyclerview
ZigzagRecyclerView
A library that gives you a slant on the traditional Grid Recycler View ♻️
Stars: ✭ 27 (-25%)
Mutual labels:  recyclerview
BaseRecyclerViewAdapter
RecyclerView通用适配器
Stars: ✭ 14 (-61.11%)
Mutual labels:  recyclerview
RecyclerViewExtensionsDemo
RecyclerView列表优化方案
Stars: ✭ 45 (+25%)
Mutual labels:  recyclerview
AdapterCommands
Drop in solution to animate RecyclerView's dataset changes by using command pattern
Stars: ✭ 74 (+105.56%)
Mutual labels:  recyclerview
RollingLayoutManager
vrgsoft.net
Stars: ✭ 57 (+58.33%)
Mutual labels:  recyclerview
recyclerview-expandable
RecyclerView implementation of traex's ExpandableLayout
Stars: ✭ 70 (+94.44%)
Mutual labels:  recyclerview
android-thinkmap-treeview
Tree View; Mind map; Think map; tree map; custom view; 自定义;关系图;树状图;思维导图;组织机构图;层次图
Stars: ✭ 314 (+772.22%)
Mutual labels:  recyclerview
TabSync
A lightweight synchronizer between Android's Tabs and Lists. Available on the View system and Jetpack Compose.
Stars: ✭ 98 (+172.22%)
Mutual labels:  recyclerview
MultiTypeAdapter
RecyclerView通用多类型适配器MultiTypeAdapter,以布局文件为单位更细粒度的条目复用。
Stars: ✭ 18 (-50%)
Mutual labels:  recyclerview
ParkingDemo
Taipei City Parking Lot Information Query System Demo
Stars: ✭ 18 (-50%)
Mutual labels:  recyclerview
FastWaiMai
仿写美团外卖电商项目
Stars: ✭ 123 (+241.67%)
Mutual labels:  recyclerview
ui
android examples for ui
Stars: ✭ 28 (-22.22%)
Mutual labels:  recyclerview
ShimmerRecyclerView
A custom Shimmer RecyclerView which adopt to list / grid transition automatically and also supports multiple view types while shimmering.
Stars: ✭ 184 (+411.11%)
Mutual labels:  recyclerview
Recycling
A Library for make an easy and faster RecyclerView without adapter
Stars: ✭ 57 (+58.33%)
Mutual labels:  recyclerview

Android - HeaderAndFooterRecyclerView

Platform License JitPack

一个为 RecyclerView 添加 HeaderViewFooterView 的方案。特征如下:

  • 对业务 Adapter 无侵入,也不需要额外的 WrapperAdapter
  • HeaderViewFooterView 直接挂载在 RecyclerView 上,无需手动处理重用问题。(特别适合将 ViewPager 用作 HeaderView 的场景)
  • 支持 LinearLayoutManagerGridLayoutManagerStaggeredGridLayoutManager 三种布局管理器的横向和纵向布局。
  • 支持多个 HeaderViewFooterView,并且可以动态添加和删除。
  • 支持动态切换 AdapterLayoutManager

Usage

repositories { 
    maven { setUrl("https://jitpack.io") }
}

dependencies {
    implementation("androidx.recyclerview:recyclerview:1.2.1")
    implementation("com.github.TakWolf.Android-HeaderAndFooterRecyclerView:hfrecyclerview:0.0.3")
}
<com.takwolf.android.hfrecyclerview.HeaderAndFooterRecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
val recyclerView = findViewById<HeaderAndFooterRecyclerView>(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)

LoadMoreFooter

该项目也提供了一个 LoadMoreFooter 用于实现加载更多的功能,通常配合下拉刷新组件一起使用。

dependencies {
    implementation("com.github.TakWolf.Android-HeaderAndFooterRecyclerView:loadmorefooter:0.0.3")
}

你需要为 LoadMoreFooter 提供一个布局,示例如下:

footer_load_more.xml

<?xml version="1.0" encoding="utf-8"?>
<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">

    <ProgressBar
        android:id="@+id/loading_bar"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_gravity="center"
        android:layout_margin="16dp"
        android:indeterminateTint="@color/app_primary"
        android:visibility="invisible"
        tools:visibility="visible" />

    <TextView
        android:id="@+id/tv_text"
        android:layout_width="match_parent"
        android:layout_height="64dp"
        android:textColor="?android:textColorSecondary"
        android:textSize="14sp"
        android:gravity="center"
        android:background="?selectableItemBackground"
        android:visibility="invisible"
        tools:text="@string/load_more_finished"
        tools:visibility="visible" />

</FrameLayout>

然后创建一个 LoadMoreFooter 的实现,示例如下(示例使用了 ViewBinding):

LoadMoreFooter.kt

class LoadMoreFooter(private val binding: FooterLoadMoreBinding) : com.takwolf.android.hfrecyclerview.loadmorefooter.LoadMoreFooter(binding.root) {
    companion object {
        fun create(layoutInflater: LayoutInflater, recyclerView: HeaderAndFooterRecyclerView): LoadMoreFooter {
            val binding = FooterLoadMoreBinding.inflate(layoutInflater, recyclerView.footerViewContainer, false)
            return LoadMoreFooter(binding)
        }
    }

    init {
        binding.tvText.setOnClickListener {
            checkDoLoadMore()
        }
        preloadOffset = 1
    }

    override fun onUpdateViews(footerView: View, @State state: Int) {
        when (state) {
            STATE_DISABLED -> {
                binding.loadingBar.visibility = View.INVISIBLE
                binding.tvText.visibility = View.INVISIBLE
                binding.tvText.text = null
                binding.tvText.isClickable = false
            }
            STATE_LOADING -> {
                binding.loadingBar.visibility = View.VISIBLE
                binding.tvText.visibility = View.INVISIBLE
                binding.tvText.text = null
                binding.tvText.isClickable = false
            }
            STATE_FINISHED -> {
                binding.loadingBar.visibility = View.INVISIBLE
                binding.tvText.visibility = View.VISIBLE
                binding.tvText.setText(R.string.load_more_finished)
                binding.tvText.isClickable = false
            }
            STATE_ENDLESS -> {
                binding.loadingBar.visibility = View.INVISIBLE
                binding.tvText.visibility = View.VISIBLE
                binding.tvText.text = null
                binding.tvText.isClickable = true
            }
            STATE_FAILED -> {
                binding.loadingBar.visibility = View.INVISIBLE
                binding.tvText.visibility = View.VISIBLE
                binding.tvText.setText(R.string.load_more_failed)
                binding.tvText.isClickable = true
            }
        }
    }
}

最后挂载到 RecyclerView 上:

val loadMoreFooter = LoadMoreFooter.create(layoutInflater, binding.recyclerView)
loadMoreFooter.setOnLoadMoreListener { 
    // do load more here
}
loadMoreFooter.addToRecyclerView(binding.recyclerView)

通过 loadMoreFooter.state 来改变组件状态。

Android-RefreshAndLoadMore-Demo 提供了一个更详细的例子用于演示下拉刷新和加载更多。

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