Hiding the Header view in ListView

后端 未结 3 1199
感动是毒
感动是毒 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:48

    Here's a blog post describing a simple way of hiding and showing the header view.

    The idea is to to put the content you wish to hide in a LinearLayout that wraps it, and hiding the content only. That way, the wrapping LinearLayout will collapse when its content is hidden, resulting in a headerView that is technically still present, but 0dip high.

    Note: If you would try to hide the content without the enclosing layout, you would be left with unwanted space in the header view.

    An example layout with a spinner representing the content:

    
          
    
    

    Then you can hide the spinner (content) as follows:

    spinnerLayout.findViewById(R.id.spinner).setVisibility(View.GONE);
    

提交回复
热议问题