1

I'm trying to create a GridView that will have two different types of items.

The first few items will take up one entire row. As the user continues to scroll, there will start to show two items per row like this:

https://i.stack.imgur.com/8loCq.jpg

How can I achieve this type of grid view? With iOS's UICollectionView it's easy to do this however I haven't had a lot of luck with this on Android. Any help would be greatly appreciated!

carlo.marinangeli
  • 2,958
  • 2
  • 17
  • 17
hexley
  • 171
  • 1
  • 2
  • 9

1 Answers1

3

The best solution here is: try to use a RecyclerView with a GridLayoutManager and set the span of the column with a SpanSizeLookup.

you can find a similar question here with a good example to start.

basically you should implement the callback SpanSizeLookup and based on the position of the items or,probably better the type, you will set the correct span.

mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            switch(mAdapter.getItemViewType(position)){
                case YourGridAdapter.TYPE_THREESPAN:
                    return 3;
                case YourGridAdapter.TYPE_ITEM:
                    return 1;
            }
        }
    });

If you are thinking about creating a your own LayoutManager, give a look to the wonderful library TwoWay View

Community
  • 1
  • 1
carlo.marinangeli
  • 2,958
  • 2
  • 17
  • 17