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.
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
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.
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