[英]Android GridView add header and footer like listview
Maybe you want to call addHeaderView()
or addFooterView()
in GridView
, which it does not have. 也许您想在GridView
调用它没有的addHeaderView()
或addFooterView()
。
It's nature that we want to add header view or a footer view to a GridView
. 我们自然希望向GridView
添加页眉视图或页脚视图。 Maybe your have been searching a long time like me, but finally find no solution. 也许您像我一样已经搜寻了很长时间,但最终找不到解决方法。
Here, I will give out an solution. 在这里,我将给出一个解决方案。
I post this answer just want people who come here can get what the want. 我发布这个答案只是希望来到这里的人们能够得到想要的东西。
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 这是一个单一文件项目,现在托管在GitHub:https://github.com/liaohuqiu/android-GridViewWithHeaderAndFooter
You can follow the link above to access the code. 您可以按照上面的链接访问代码。 Happy coding. 快乐的编码。
To add a Header to the GridView, use the HeaderGridView
by Google. 要将标题添加到GridView,请使用Google的HeaderGridView
。
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
,你就可以使用下面的行添加标题:
gridView.addHeaderView(customView);
Actually you can create layout with two columns and use ListView. 实际上,您可以创建具有两列的布局并使用ListView。 In getView you should manipulate with columns and set there some data. 在getView中,您应该使用列进行操作并在那里设置一些数据。
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/munix/GridViewHeader
https://github.com/TonicArtos/StickyGridHeaders https://github.com/TonicArtos/StickyGridHeaders
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.