The principles of gone and invisible for view in Android

Source: Internet
Author: User

Only two sentences are repeated in nonsense;

Gone is really hidden;

The invisible is not visible but the location of the view is reserved;

Online repetition of these two sentences with examples, and do not observe the nature to make a distinction. See the source after the difference hope that the vast number of friends can learn from, the source code as follows:

 /*Check If the GONE bit has changed*/        if((Changed & GONE)! = 0) {needglobalattributesupdate (false);            requestlayout (); if(((Mviewflags & visibility_mask) = =GONE)) {                if(Hasfocus ()) Clearfocus ();                Clearaccessibilityfocus ();                Destroydrawingcache (); if(mparentinstanceofView) {                    //GONE views NoOp invalidation, so invalidate the parent                   (View) mparent). Invalidate (True); }                //Mark The view drawn to ensure that it gets invalidated properly the next//Time It is visible and gets invalidatedMprivateflags |=Pflag_drawn; }            if(Mattachinfo! =NULL) {mattachinfo.mviewvisibilitychanged=true; }        }        /*Check If the VISIBLE bit has changed*/        if((Changed & INVISIBLE)! = 0) {needglobalattributesupdate (false); /** If This view was becoming invisible, set the drawn flag so that * the next invalidate () would             Not being skipped. */Mprivateflags|=Pflag_drawn; if(((Mviewflags & visibility_mask) = =INVISIBLE)) {                //root view becoming invisible shouldn ' t clear focus and accessibility focus                if(Getrootview ()! = This) {                    if(Hasfocus ()) Clearfocus ();                Clearaccessibilityfocus (); }            }            if(Mattachinfo! =NULL) {mattachinfo.mviewvisibilitychanged=true; }        }

If both gone and invisible can achieve your results, then you should choose invisible. Because from the source view gone need to re-layout and notify the upper view to refresh, there are caches to empty the cache, from the view of the cost of change invisible to be more cost-effective, if your view is not very resource-intensive situation!!! You are also very welcome to say what you think .

The principles of gone and invisible for view in Android

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.