|
4 | 4 | import android.content.Context;
|
5 | 5 | import android.support.annotation.DrawableRes;
|
6 | 6 | import android.support.annotation.IntDef;
|
| 7 | +import android.support.v7.widget.GridLayoutManager; |
7 | 8 | import android.support.v7.widget.LinearLayoutManager;
|
8 | 9 | import android.support.v7.widget.RecyclerView;
|
9 | 10 | import android.support.v7.widget.StaggeredGridLayoutManager;
|
@@ -364,9 +365,22 @@ public void onBindViewHolder(ViewHolder holder, int position) {
|
364 | 365 | mAdapter.onBindViewHolder(holder, position);
|
365 | 366 | } else {
|
366 | 367 | if (getLayoutManager() instanceof StaggeredGridLayoutManager) {
|
367 |
| - StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) (getLayoutManager()).generateDefaultLayoutParams(); |
368 |
| - layoutParams.setFullSpan(true); |
369 |
| - holder.itemView.setLayoutParams(layoutParams); |
| 368 | + ViewGroup.LayoutParams layoutParams = holder.itemView.getLayoutParams(); |
| 369 | + if (layoutParams instanceof StaggeredGridLayoutManager.LayoutParams) { |
| 370 | + ((StaggeredGridLayoutManager.LayoutParams) layoutParams).setFullSpan(true); |
| 371 | + } |
| 372 | + } else if (getLayoutManager() instanceof GridLayoutManager) { |
| 373 | + final GridLayoutManager layoutManager = (GridLayoutManager) getLayoutManager(); |
| 374 | + layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { |
| 375 | + @Override |
| 376 | + public int getSpanSize(int position) { |
| 377 | + int viewType = getAdapter().getItemViewType(position); |
| 378 | + if (viewType < 0) { |
| 379 | + return layoutManager.getSpanCount(); |
| 380 | + } |
| 381 | + return 1; |
| 382 | + } |
| 383 | + }); |
370 | 384 | }
|
371 | 385 | if (holder instanceof VH) {
|
372 | 386 | ((VH) holder).onBindViewHolder();
|
|
0 commit comments