@Override public void onBindViewHolder(final ViewHolder holder, final int position) { if (isItem(position)) { mAdapter.onBindViewHolder(holder, position - getHeadersCount()); } else { if (mLayoutManager != null && mLayoutManager instanceof StaggeredGridLayoutManager) { LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); params.setFullSpan(true); holder.itemView.setLayoutParams(params); } } }
private void setFullSpan(View view, LayoutManager layoutManager) { int itemHeight = view.getLayoutParams() != null ? view.getLayoutParams().height : -2; if (layoutManager instanceof StaggeredGridLayoutManager) { LayoutParams layoutParams = new LayoutParams(-1, itemHeight); layoutParams.setFullSpan(true); view.setLayoutParams(layoutParams); } else if (layoutManager instanceof GridLayoutManager) { view.setLayoutParams(new ViewGroup.LayoutParams(-1, itemHeight)); } notifyDataSetChanged(); }