Java Code Examples for android.support.v7.widget.GridLayoutManager#SpanSizeLookup

The following examples show how to use android.support.v7.widget.GridLayoutManager#SpanSizeLookup . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WrapperUtils.java    From Bailan with Apache License 2.0 6 votes vote down vote up
public static void onAttachedToRecyclerView(RecyclerView.Adapter innerAdapter, RecyclerView recyclerView, final SpanSizeCallback callback) {
    innerAdapter.onAttachedToRecyclerView(recyclerView);

    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        final GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup();

        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                return callback.getSpanSize(gridLayoutManager, spanSizeLookup, position);
            }
        });
        gridLayoutManager.setSpanCount(gridLayoutManager.getSpanCount());
    }
}
 
Example 2
Source File: SimpleRecyclerView.java    From SimpleRecyclerView with Apache License 2.0 6 votes vote down vote up
public void useGridMode(int spanCount) {
  setGridSpanCount(spanCount);
  setLayoutManager(new GridLayoutManager(getContext(), spanCount));

  GridLayoutManager.SpanSizeLookup spanSizeLookup = new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
      try {
        return adapter.getCell(position).getSpanSize();
      } catch (Exception e) {
        return 1;
      }
    }
  };
  spanSizeLookup.setSpanIndexCacheEnabled(true);
  ((GridLayoutManager) getLayoutManager()).setSpanSizeLookup(spanSizeLookup);
}
 
Example 3
Source File: WrapperUtils.java    From baseAdapter with Apache License 2.0 6 votes vote down vote up
public static void onAttachedToRecyclerView(RecyclerView.Adapter innerAdapter, RecyclerView recyclerView, final SpanSizeCallback callback)
{
    innerAdapter.onAttachedToRecyclerView(recyclerView);

    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        final GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup();

        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup()
        {
            @Override
            public int getSpanSize(int position)
            {
                return callback.getSpanSize(gridLayoutManager, spanSizeLookup, position);
            }
        });
        gridLayoutManager.setSpanCount(gridLayoutManager.getSpanCount());
    }
}
 
Example 4
Source File: WrapperUtils.java    From likequanmintv with Apache License 2.0 6 votes vote down vote up
public static void onAttachedToRecyclerView(RecyclerView.Adapter innerAdapter, RecyclerView recyclerView, final SpanSizeCallback callback)
{
    innerAdapter.onAttachedToRecyclerView(recyclerView);

    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        final GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup();

        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup()
        {
            @Override
            public int getSpanSize(int position)
            {
                return callback.getSpanSize(gridLayoutManager, spanSizeLookup, position);
            }
        });
        gridLayoutManager.setSpanCount(gridLayoutManager.getSpanCount());
    }
}
 
Example 5
Source File: SwipeRecyclerView.java    From SwipeRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
public void setLayoutManager(LayoutManager layoutManager) {
    if (layoutManager instanceof GridLayoutManager) {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager)layoutManager;
        final GridLayoutManager.SpanSizeLookup spanSizeLookupHolder = gridLayoutManager.getSpanSizeLookup();

        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                if (mAdapterWrapper.isHeader(position) || mAdapterWrapper.isFooter(position)) {
                    return gridLayoutManager.getSpanCount();
                }
                if (spanSizeLookupHolder != null) {
                    return spanSizeLookupHolder.getSpanSize(position - getHeaderCount());
                }
                return 1;
            }
        });
    }
    super.setLayoutManager(layoutManager);
}
 
Example 6
Source File: WrapperUtils.java    From MVVM-JueJin with MIT License 6 votes vote down vote up
public static void onAttachedToRecyclerView(RecyclerView.Adapter innerAdapter, RecyclerView recyclerView, final SpanSizeCallback callback)
{
    innerAdapter.onAttachedToRecyclerView(recyclerView);

    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        final GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup();

        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup()
        {
            @Override
            public int getSpanSize(int position)
            {
                return callback.getSpanSize(gridLayoutManager, spanSizeLookup, position);
            }
        });
        gridLayoutManager.setSpanCount(gridLayoutManager.getSpanCount());
    }
}
 
Example 7
Source File: GridSpaceDecoration.java    From ItemDecorationDemo with Apache License 2.0 5 votes vote down vote up
protected boolean isLastRaw(int pos) {
    if (mChildCount <= 0) {
        return false;
    }
    GridLayoutManager.SpanSizeLookup lookup = mManager.getSpanSizeLookup();
    return lookup.getSpanGroupIndex(pos, mSpanCount) == lookup.getSpanGroupIndex(mChildCount - 1, mSpanCount);
}
 
Example 8
Source File: FlexibleDividerDecoration.java    From AccountBook with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a group index for GridLayoutManager.
 * for LinearLayoutManager, always returns position.
 *
 * @param position current view position to draw divider
 * @param parent   RecyclerView
 * @return group index of items
 */
private int getGroupIndex(int position, RecyclerView parent) {
    if (parent.getLayoutManager() instanceof GridLayoutManager) {
        GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
        GridLayoutManager.SpanSizeLookup spanSizeLookup = layoutManager.getSpanSizeLookup();
        int spanCount = layoutManager.getSpanCount();
        return spanSizeLookup.getSpanGroupIndex(position, spanCount);
    }

    return position;
}
 
Example 9
Source File: WrapperSpanSizeLookup.java    From NoPaginate with Apache License 2.0 5 votes vote down vote up
public WrapperSpanSizeLookup(GridLayoutManager.SpanSizeLookup gridSpanSizeLookup,
                             BaseGridLayoutManagerItem loadingListItemSpanLookup,
                             WrapperAdapter wrapperAdapter) {
    this.wrappedSpanSizeLookup = gridSpanSizeLookup;
    this.loadingListItemSpanLookup = loadingListItemSpanLookup;
    this.wrapperAdapter = wrapperAdapter;
}
 
Example 10
Source File: NoPaginate.java    From NoPaginate with Apache License 2.0 5 votes vote down vote up
/**
 * This method unsubscribe observer and change listeners reference to null
 * for avoid memory leaks.
 */
public void unbind() {
    recyclerView.removeOnScrollListener(scrollListener);

    if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
        wrapperAdapter.unbind();
        userAdapter.unregisterAdapterDataObserver(wrapperAdapterObserver);
        recyclerView.setAdapter(userAdapter);

    } else if (recyclerView.getLayoutManager() instanceof GridLayoutManager && wrapperSpanSizeLookup != null) {
        GridLayoutManager.SpanSizeLookup spanSizeLookup = wrapperSpanSizeLookup.getWrappedSpanSizeLookup();
        ((GridLayoutManager) recyclerView.getLayoutManager()).setSpanSizeLookup(spanSizeLookup);
    }
}
 
Example 11
Source File: Paginate.java    From NoPaginate with Apache License 2.0 5 votes vote down vote up
/**
 * This method unsubscribe observer and change listeners reference to null
 * for avoid memory leaks.
 */
@Deprecated
public void unbind() {
    if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
        wrapperAdapter.unbind();
        userAdapter.unregisterAdapterDataObserver(wrapperAdapterObserver);
        recyclerView.setAdapter(userAdapter);

    } else if (recyclerView.getLayoutManager() instanceof GridLayoutManager && wrapperSpanSizeLookup != null) {
        GridLayoutManager.SpanSizeLookup spanSizeLookup = wrapperSpanSizeLookup.getWrappedSpanSizeLookup();
        ((GridLayoutManager) recyclerView.getLayoutManager()).setSpanSizeLookup(spanSizeLookup);
    }
}
 
Example 12
Source File: AutofitRecyclerView.java    From uPods-android with Apache License 2.0 4 votes vote down vote up
public void setSpanSizeLookup(GridLayoutManager.SpanSizeLookup spanSizeLookup) {
    manager.setSpanSizeLookup(spanSizeLookup);
}
 
Example 13
Source File: SpanSizeLookupWrapper.java    From SupportSwipeLoadmore with GNU General Public License v3.0 4 votes vote down vote up
public GridLayoutManager.SpanSizeLookup getWrapper() {
    return wrapper;
}
 
Example 14
Source File: WrapperUtils.java    From CoordinatorLayoutExample with Apache License 2.0 4 votes vote down vote up
int getSpanSize(GridLayoutManager layoutManager, GridLayoutManager.SpanSizeLookup
oldLookup, int position);
 
Example 15
Source File: LightAdapter.java    From LightAdapter with Apache License 2.0 4 votes vote down vote up
public GridLayoutManager.SpanSizeLookup spanSizeLookup(int headerSpan, int footerSpan) {
    return new AdapterSpanSizeLookup(headerSpan, footerSpan);
}
 
Example 16
Source File: DStaggeredGridLayoutManager.java    From Pas with Apache License 2.0 2 votes vote down vote up
public void setSpanSizeLookup(GridLayoutManager.SpanSizeLookup spanSizeLookup) {
    mSpanSizeLookup = spanSizeLookup;

}
 
Example 17
Source File: ExStaggeredGridLayoutManager.java    From ExRecyclerView with Apache License 2.0 2 votes vote down vote up
/**
 * 设置某个位置的item的跨列程度,这里和GridLayoutManager有点不一样,
 * 如果你设置某个位置的item的span>1了,那么这个item会占据所有列
 *
 * @param spanSizeLookup instance to be used to query number of spans
 *                       occupied by each item
 */
public void setSpanSizeLookup(GridLayoutManager.SpanSizeLookup spanSizeLookup) {
    mSpanSizeLookup = spanSizeLookup;
}
 
Example 18
Source File: WrapperUtils.java    From Bailan with Apache License 2.0 votes vote down vote up
int getSpanSize(GridLayoutManager layoutManager, GridLayoutManager.SpanSizeLookup oldLookup, int position); 
Example 19
Source File: WrapperUtils.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 votes vote down vote up
int getSpanSize(GridLayoutManager layoutManager, GridLayoutManager.SpanSizeLookup oldLookup, int position); 
Example 20
Source File: WrapperUtils.java    From SmartChart with Apache License 2.0 votes vote down vote up
int getSpanSize(GridLayoutManager layoutManager, GridLayoutManager.SpanSizeLookup oldLookup, int position);