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?
Asked
Active
Viewed 941 times
1 Answers
6
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);
}

tyczj
- 71,600
- 54
- 194
- 296
-
how to implement that? should i change my adapter too? – wanz Apr 26 '16 at 17:43
-
i use onBinViewHolder to fill content of each reyclerview item, what the purpose create layoutParams in there? – wanz Apr 27 '16 at 08:20
-
I dont understand the question, you dont create anything in there you set the span to full width anytime you want to create a row that is a header – tyczj Apr 27 '16 at 17:42
-
life saver! `layoutParams.setFullSpan( true );` works like charm – injecteer Apr 28 '16 at 09:03