Everyone knows that GridView does not supports headers and footers like a ListView.
There is a few ways to implementing this:
- Use a ListView and form columnt manually via ViewGroups. It not works for me, because it's require a lot of layout operations like measuring and layouting, and it's difficult to implement draw selector on top.
- Use special adapter. It works fine with a footer: we should fill last cells with a
Space
and manually insert after them out footer with width that equals GridView width. But this not works with headers: although header is stretched, next cells float on it. - Use a GridLayout. GridLayout is good, but what about performance with 500-1000 cells? AdapterView supports caching and reusing Views, as far as I know, this is not possible with GridLayout.
Extend GridView and write custom class, that allows to draw a header before the grid content. It's difficult, but it's should work very fast. Let's try to figure out how to do this:
- Measure the header. It's very simple, I have not questions about this.
- Layout header in the top of the grid. We also should consider with scrolling position to allow move header with whole grid content, so my first question is: how to know where bottom border should be located while scrolling?
- Layout whole grid content after the header. How to do that? I've newer do this before.
- Dispatch draw to the header view too and resolve overscrolling effect if it's not work well.
- Handle the scroll event and refresh header position.
So what you can suggest me? How to do header offset? Is it right to invoke relayouting with every scroll event?