The header in the ListView, Footer view should be encountered, for example, when scrolling to the bottom, automatically start loading, for some application market, will add Viewflipper in the header to do the application recommendation (the kind of scrolling, It seems that many markets have this function).
When you add, you will generally do the following:
[Java]View Plaincopyprint?
- ListView listview = xxxx;
- Listview.addhearderview (Item_head);
- Listview.setadapter (adapter);
After the page is displayed normally, if the user refreshes and finds no application to recommend, this time the ListView header needs to be hidden. The first thing to think about is:
[Java]View Plaincopyprint?
- Item_head.setvisibility (View.gone);
Yes, the content really disappears, but the position is still occupied, the page shows a blank area!
As for the solution, some people say that setting the header neutron view is not visible; some people say that setting the header neutron view height is 0; But I'm testing it here.
Current My solution:
[Java]View Plaincopyprint?
- Item_head.setpadding (0,-1 * headcontentheight, 0, 0);
- Item_head.setvisibility (View.gone);
Finally, I would like to say that this problem feels really painful! Record here and do the memo!
In Android development, when using the ListView, we often use the Footerview or Headerview, add the footer and header to the ListView a lot of times, will be hidden and displayed according to the situation.
Because footer and headers use the methods of deletion and addition, they always feel bad.
When you set the view in footer and header directly to gone, the area is still occupied, although the content is not displayed.
Through various methods of testing, and finally to a perfect solution to the problem of the method, the following code:
This.footerLayout.setVisibility (View.gone);
This.footerLayout.setPadding (0,-footerlayout.getheight (), 0, 0);
It means moving the content up to the height of the view.
Of course, when it needs to be displayed, it is also set back (do an if else process)
This.footerLayout.setVisibility (view.visible);
This.footerLayout.setPadding (0, 0, 0, 0);
Reference:
Http://stackoverflow.com/questions/4317778/hide-footer-view-in-listview
Http://blog.sina.com.cn/s/blog_70b9730f01014sgm.html
[Android Bug] The header in the ListView, footer cannot hide (gone) The problem