CymChad / BaseRecyclerViewAdapterHelper

BRVAH:Powerful and flexible RecyclerAdapter
http://www.recyclerview.org/
MIT License
24.3k stars 5.15k forks source link

4.0版本,HeaderView和TrailingLoadStateAdapter再GridLayoutManager中展示样式错误 #3839

Closed AndroidBread closed 9 months ago

AndroidBread commented 9 months ago

Screenshot_20240104_102910

代码:

    binding.rvTest.layoutManager = GridLayoutManager(requireContext(), 2)
    // 实例化自定义"加载更多"的类
    val loadMoreAdapter = CustomLoadMoreAdapter()
    loadMoreAdapter.isAutoLoadMore = false
    loadMoreAdapter.setOnLoadMoreListener(object : TrailingLoadStateAdapter.OnTrailingListener {
        override fun onLoad() {
            request()
        }
        override fun onFailRetry() {
            request()
        }
        override fun isAllowLoading(): Boolean {
            // 是否允许触发“加载更多”,通常情况下,下拉刷新的时候不允许进行加载更多
            return !binding.refreshLayout.isRefreshing
        }
    })
    helper = QuickAdapterHelper.Builder(mAdapter)
        .setTrailingLoadStateAdapter(loadMoreAdapter) // 传递自定义的“加载跟多”
        .build()
    binding.rvTest.adapter = helper.adapter
AndroidBread commented 9 months ago

如图,无论是header还是加载更多。都只展示了GridLayoutManager中的一个条目的宽度。想问一下有没有做对应的适配。可以让头尾布局宽度可以满屏。

AndroidBread commented 9 months ago

看源码找到解决方案了。轮子中提供了QuickGridLayoutManager + FullSpanAdapterType的方式,可以实现网格布局下满跨度展示。需要满跨度展示的头尾布局adapter需要实现FullSpanAdapterType接口,对应的recyclerview需要使用QuickGridLayoutManager。

AndroidBread commented 8 months ago

使用多类型item布局,RecyclerView使用QuickGridLayoutManager布局管理器,你需要横向撑满的item实现FullSpanAdapterType接口就可以了。

2024年2月2日 16:36,Flash @.***> 写道:

你这种方案只能解决header和footer的横向撑满屏幕问题吧,如果网格布局里,某个item需要横向撑满布局呢?这个框架似乎没有提供一些合适的范例?

— Reply to this email directly, view it on GitHub https://github.com/CymChad/BaseRecyclerViewAdapterHelper/issues/3839#issuecomment-1923327534, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADZUEZSXBAETT2OCVHY3T3TYRSQRPAVCNFSM6AAAAABBMI4MUWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRTGMZDONJTGQ. You are receiving this because you modified the open/close state.