Android GridView add header and footer like listview

走远了吗. 提交于 2019-11-30 09:51:25

I post this answer just want people who come here can get what the want.

Let's have a look the screen snapshot.

the usage is very simple

GridViewWithHeaderAndFooter gridView = (GridViewWithHeaderAndFooter) v.findViewById(R.id.ly_image_list_grid);

LayoutInflater layoutInflater = LayoutInflater.from(this);
View headerView = layoutInflater.inflate(R.layout.test_header_view, null);
View footerView = layoutInflater.inflate(R.layout.test_footer_view, null);
gridView.addHeaderView(headerView);
gridView.addFooterView(footerView);

It'a single file project, now it hosts at GitHub: https://github.com/liaohuqiu/android-GridViewWithHeaderAndFooter

You can follow the link above to access the code. Happy coding.

Sami Eltamawy

To add a Header to the GridView, use the HeaderGridView by Google.

Just copy this class into your project and use it instead of the default GridView, and you will be able to add header using the following line:

 gridView.addHeaderView(customView);

Source: answer

Actually you can create layout with two columns and use ListView. In getView you should manipulate with columns and set there some data.

Also you can create just one column in first and last row. It will look like header or footer.

Besides, you can look through these links:

https://github.com/munix/GridViewHeader

https://github.com/TonicArtos/StickyGridHeaders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!