Android GridView 像列表视图一样添加页眉和页脚 [英] Android GridView add header and footer like listview
问题描述
也许您想在 GridView
中调用 addHeaderView()
或 addFooterView()
,但它没有.
Maybe you want to call addHeaderView()
or addFooterView()
in GridView
, which it does not have.
我们想要向 GridView
添加页眉视图或页脚视图是很自然的.可能你和我一样找了很久,都没有解决办法.
It's nature that we want to add header view or a footer view to a 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);
这是一个单文件项目,现在托管在 GitHub: https://github.com/liaohuqiu/android-GridViewWithHeaderAndFooter
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.
这篇关于Android GridView 像列表视图一样添加页眉和页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!