Can a GridView have a footer and header just like ListView?

前端 未结 11 2013
北海茫月
北海茫月 2020-12-14 16:29

A quick question:

In ListView I use this code:

list.addHeaderView(headerView);

How to deal with it when working on

相关标签:
11条回答
  • 2020-12-14 17:07

    You can use AsymmetricGridView and specify headers/footers with a bigger rowSpan so they would take the entire row.

    0 讨论(0)
  • 2020-12-14 17:09

    There is no support for header or footer views with GridView, sorry.

    0 讨论(0)
  • 2020-12-14 17:11

    There is a quite good implementation of GridView with header support in Google Photos application, as it's OSS code you can use it as is or take it as a reference for your own implementation: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.3_r2.1/com/android/photos/views/HeaderGridView.java

    Basic idea is quite simple - WrapperAdapter creates an fake row by increasing number of items by number of columns and then return a header view for the item.

    0 讨论(0)
  • 2020-12-14 17:12

    You could use this library, http://tonicartos.github.io/StickyGridHeaders/

    which allows you to create headers that are sticky (for grouping the list and keeping the header visible for the current group). You can turn off the sticky feature as well.

    0 讨论(0)
  • 2020-12-14 17:12

    There is a way to accomplish the desired functionality WITHOUT using a library or anything.

    EDIT: Just borrow the HeaderGridView Implementation by google, see Here
    You could also customize it for footer. The below suggestion is just too complicated and required more tweaking. Without going into specific details, all you need to do is this.

    1) Subclass GridView
    2) override onScrollChanged
    3) Calculate the offset everytime it scrolls
    4) Set the parentView(view that contains the headerView and gridview) translation y to -Offset.(view.setTranslationY(-offset). Also have an if statement to that once it reaches a certain offset it would stop scrolling.
    5) obviously you want to structure this well so your gridview can have a method like attachToGridview(View view). I have a complete implementation of this which works.
    See Scroll offset of GridView for help on getting offset since GridView has a bug were the views get recycled.

    0 讨论(0)
提交回复
热议问题