android.support.v7.widget.GridLayoutManager.SpanSizeLookup Java Examples

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: X8sPanelRecycleAdapter.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    LayoutManager manager = recyclerView.getLayoutManager();
    if (manager instanceof GridLayoutManager) {
        ((GridLayoutManager) manager).setSpanSizeLookup(new SpanSizeLookup() {
            public int getSpanSize(int position) {
                if (X8sPanelRecycleAdapter.this.isHeadView(position)) {
                    return X8sPanelRecycleAdapter.this.headCount;
                }
                if (X8sPanelRecycleAdapter.this.isCategoryType(position)) {
                    return X8sPanelRecycleAdapter.this.headSpanCount;
                }
                return X8sPanelRecycleAdapter.this.bodySpanCount;
            }
        });
    }
}
 
Example #2
Source File: EasyHeaderFooterAdapter.java    From easy-header-footer-adapter with MIT License 6 votes vote down vote up
private void initLayoutManager(final RecyclerView.LayoutManager layoutManager) {
    this.layoutManager = layoutManager;

    if (layoutManager instanceof GridLayoutManager) {
        final GridLayoutManager castedLayoutManager = (GridLayoutManager) layoutManager;
        final SpanSizeLookup existingLookup = castedLayoutManager.getSpanSizeLookup();

        castedLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                if (isHeader(position) || isFooter(position)) {
                    return castedLayoutManager.getSpanCount();
                }

                return existingLookup.getSpanSize(getRealPosition(position));
            }
        });
    }
}
 
Example #3
Source File: BaseRecycleAdapter.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    LayoutManager manager = recyclerView.getLayoutManager();
    if (manager instanceof GridLayoutManager) {
        ((GridLayoutManager) manager).setSpanSizeLookup(new SpanSizeLookup() {
            public int getSpanSize(int position) {
                if (BaseRecycleAdapter.this.isCategoryType(position)) {
                    return BaseRecycleAdapter.this.headSpanCount;
                }
                return BaseRecycleAdapter.this.bodySpanCount;
            }
        });
    }
}
 
Example #4
Source File: ChannelWallActivity.java    From letv with Apache License 2.0 5 votes vote down vote up
private void init() {
    GridLayoutManager manager = new GridLayoutManager(this, 4);
    this.mRecyclerView.setLayoutManager(manager);
    ItemTouchHelper helper = new ItemTouchHelper(new ItemDragHelperCallback());
    helper.attachToRecyclerView(this.mRecyclerView);
    this.mAdapter = new ChannelFragmentAdapter(this, helper, this.mChannelListBean, this.mRecyclerView);
    this.mAdapter.setFrom(this.mFromMineCustom);
    manager.setSpanSizeLookup(new SpanSizeLookup(this) {
        final /* synthetic */ ChannelWallActivity this$0;

        {
            if (HotFix.PREVENT_VERIFY) {
                System.out.println(VerifyLoad.class);
            }
            this.this$0 = this$0;
        }

        public int getSpanSize(int position) {
            int viewType = this.this$0.mAdapter.getItemViewType(position);
            if (viewType == 2 || viewType == 1) {
                return 1;
            }
            return 4;
        }
    });
    this.mRecyclerView.setAdapter(this.mAdapter);
}