android - 如何用GridView实现展开和收起的功能
高洛峰
高洛峰 2017-04-17 17:41:49
0
4
846


这是默认收起来的,点击展开实现显示全部内容:


这该如何实现?????

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(4)
迷茫

There are many solutions to this problem. I will choose to click to expand and add all the remaining items to the adapter. Just update it. If you want to collapse it, just remove the items that need to be collapsed from the adapter. Here you need to do additional processing on the click event of the last item.

Peter_Zhu

Get the layoutParams of this gridView, and then set its height, similar to this
ViewGroup.LayoutParams layoutParams = gridView.getLayoutParams();
layoutParams.height = 300;

Generally, a transition animation will be used for such an effect. The principle is the same, except that the thing done once is done multiple times (the height gradually becomes larger)

刘奇

In fact, this effect does not need to be done with GridView. According to your description, there is no need for sliding, so it can be done with GridLayout. After clicking, remove the last one and then add it and then add it. - Not complicated The logic is also clear.

刘奇

Our company implements this requirement by setting a mark attribute to record the expanded and collapsed status, and rewriting the return value of the adapter's getItemCount(). According to this mark attribute, 8 is returned when collapsed, and the expansion is Return the total number

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template