search

Home  >  Q&A  >  body text

android - 如何用GridView实现展开和收起的功能


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


这该如何实现?????

高洛峰高洛峰2887 days ago842

reply all(4)I'll reply

  • 迷茫

    迷茫2017-04-17 17:43:49

    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.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 17:43:49

    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)

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:43:49

    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.

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:43:49

    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

    reply
    0
  • Cancelreply