Hiding the Header view in ListView

后端 未结 3 1243
感动是毒
感动是毒 2021-02-12 13:07

I\'m trying to add a header view to my list, and hide it all the time unless we scroll to it (like the pull-to-refresh mechanism). The problem is: if the list is not tall enough

3条回答
  •  无人及你
    2021-02-12 13:56

    Here is a solution for the current PullToRefreshListView (updated November 4, 2011):
    https://github.com/johannilsson/android-pulltorefresh

    based on the Hiding Header Views article:
    http://pivotallabs.com/users/joe/blog/articles/1759-android-tidbits-6-22-2011-hiding-header-views

    1) Copy pull_to_refresh_header.xml from the library's res/layout to your app's res/layout.

    2) Edit your app's pull_to_refresh_header.xml. Wrap topmost RelativeLayout in a LinearLayout and then wrap the LinearLayout in a RelativeLayout again. Why? Topmost layout must be RelativeLayout because that's what's expected in code, second level layout must be LinearLayout because that's the only layout that collapses with View.GONE. Third level layout must be the same as original top-level RelativeLayout (except id) to preserve look.

    3) Preserve same id on top RelativeLayout (pull_to_refresh_header), give second level LinearLayout an id of your choosing, give third level RelativeLayout another id (pull_to_refresh_header2 for example).

    4) Move all padding from the topmost RelativeLayout to the second RelativeLayout.

    5) In your code use findViewById and your LinearLayout id to set visibility to View.GONE. The LinearLayout will collapse, and if you moved all padding values appropriately to the inner RelativeLayout the header should take no space at all.

提交回复
热议问题