【问题标题】:How to add headerview to recyclerview with staggeredGridLayoutManager如何使用 staggeredGridLayoutManager 将 headerview 添加到 recyclerview
【发布时间】:2016-04-26 17:35:47
【问题描述】:

我想使用 staggeredGridLayoutManager 将类似 listview 的 headerview 添加到 recyclerview 中。我搜索了所有库,只找到了这个RecyclerHeaderView,但这个库对 LinearLayoutManager 或 GridLayoutManager 有限制。是否可以为 staggeredGridLayout 添加 headerview?

【问题讨论】:

    标签: android android-recyclerview staggeredgridlayout


    【解决方案1】:

    您可以在布局管理器中使用setFullSpan 来创建一个看起来像标题的行

    public final void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
    
        StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) viewHolder.itemView.getLayoutParams();
        layoutParams.setFullSpan(true);
    }
    

    【讨论】:

    • 如何实现?我也应该更换适配器吗?
    • 我使用 onBinViewHolder 填充每个 reyclerview 项目的内容,在那里创建 layoutParams 的目的是什么?
    • 我不明白这个问题,你没有在其中创建任何东西,只要你想创建一个作为标题的行,你就可以将跨度设置为全宽
    • 救命! layoutParams.setFullSpan( true ); 像魅力一样工作
    猜你喜欢
    • 2020-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-21
    • 2015-01-07
    • 1970-01-01
    • 2018-09-20
    相关资源
    最近更新 更多