5

How do i have a GridView with some cells that span across columns? I have a several sets of data that need to be dynamically loaded(so grid layout is not what i need) and visually presented in different ways on the GridView. Below is a graphical representation of what i'm able to achieve, the 'x' shows cells that display something while the empty cells don't show anything

Unwanted

With what i have here, there's an ugly cell at the center when I want to display 4 items in one row.

What i want is to be able to have one row evenly displaying 5 items, while another row can display 4 items and so on.. The graphic below shows what i want to achieve

Wanted

I want to use the Gridview because the data to populate the grid is provided dynamically. So i'm able to use the gridview's adapter. If there's another approach to this other than the gridview then i'm open for suggestions.

Community
  • 1
  • 1
kev
  • 1,148
  • 2
  • 14
  • 29

1 Answers1

0

Late answer.. You can not use a GridView component for that because it works in terms of columns. The column count must be defined.

What you can do is to use a custom LayoutManager for RecyclerView. Here is a good example. RecyclerView LayoutManager different span counts on different rows

There is a lot of information on this topic nowadays because this kind of customization is the main purpose of RecyclerView. Google apps use this to follow material design pattern.

Community
  • 1
  • 1
Gennadii Saprykin
  • 4,505
  • 8
  • 31
  • 41