[Android Bug] The header in the ListView, footer cannot hide (gone) The problem

Source: Internet
Author: User

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?
    1. ListView listview = xxxx;
    2. Listview.addhearderview (Item_head);
    3. 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?
    1. 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?
    1. Item_head.setpadding (0,-1 * headcontentheight, 0, 0);
    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.