How to spread evenly two view types with different sizes in RecyclerView?

I've added a new view type for the native ad view in my RecyclerView but I can't figure out how to spread the items evenly across the entire screen. After every 12th element, the new view type should be inserted.

This is what I want:

enter image description here

And this is what I get:

enter image description here

The result from the 2nd picture is achieved using this code:

gridLayoutManager = new GridLayoutManager(mActivity, 6);
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                switch (emotesAdapter.getItemViewType(position)) {
                    case AD_TYPE:
                        return gridLayoutManager.getSpanCount();
                    case CONTENT_TYPE:
                        return 1;
                    default:
                        return -1;
                }
            }
        });

        recyclerView.setLayoutManager(gridLayoutManager);

Any ideas?



from Recent Questions - Stack Overflow https://ift.tt/3GztSwL
https://ift.tt/3EmLvho

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations