本文介绍了如何使用staggeredGridLayoutManager将headerview添加到recyclerview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用staggeredGridLayoutManager将像listview这样的headerview添加到recyclerview中.我已经搜索了所有库,只找到了一个 RecyclerHeaderView ,但是该库对LinearLayoutManager或GridLayoutManager有所限制.可以为staggeredGridLayout添加headerview吗?
I want add a headerview like listview into recyclerview with staggeredGridLayoutManager. I have search all library and only found this one RecyclerHeaderView but this library have limitation for LinearLayoutManager or GridLayoutManager. Is possible to add headerview for staggeredGridLayout?
推荐答案
,您可以使用 setFullSpan 来创建看起来像标题的行
you can use setFullSpan in the layout manager to create a row that looks like a header
public final void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) viewHolder.itemView.getLayoutParams();
layoutParams.setFullSpan(true);
}
这篇关于如何使用staggeredGridLayoutManager将headerview添加到recyclerview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!