How to add headerview to recyclerview with staggeredGridLayoutManager

百般思念 提交于 2019-12-11 13:11:13

问题


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?


回答1:


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);
}


来源:https://stackoverflow.com/questions/36871947/how-to-add-headerview-to-recyclerview-with-staggeredgridlayoutmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!