The difference between removeallviews () and Removeallviewsinlayout () in ViewGroup

Source: Internet
Author: User

Below is the source code of Removeallviewsinlayout ()

/** * Called by a viewgroup subclass to remove child views from itself, * when it must first know its size on scre En before it can calculate how many * child views it would render.      An example was a Gallery or a ListView, which * may "has" children, but actually only render the number of children * That can currently fit inside the object in screen. Do not call * This method unless you is extending viewgroup and understand the * view measuring and layout Pipeli     Ne.        */public void Removeallviewsinlayout () {final int count = Mchildrencount;        if (count <= 0) {return;        } final view[] children = Mchildren;        Mchildrencount = 0;        Final View focused = mfocused;        Final Boolean detach = mattachinfo! = NULL;        View clearchildfocus = null;        Needglobalattributesupdate (FALSE);            for (int i = count-1; I >= 0; i--) {final view view = Children[i]; if (mtransition!)= null) {Mtransition.removechild (this, view);                } if (view = = focused) {view.clearfocusforremoval ();            Clearchildfocus = view;                    } if (View.getanimation ()! = NULL | | (Mtransitioningviews! = null && mtransitioningviews.contains (view)))            {Adddisappearingview (view);            } else if (detach) {View.dispatchdetachedfromwindow ();            } onviewremoved (view);            View.mparent = null;        Children[i] = null;        } if (Clearchildfocus! = null) {Clearchildfocus (clearchildfocus); }    }


Method Removeallviews () of the source code

/** * Call this method to remove all child views from the     * viewgroup.     */Public    void Removeallviews () {        removeallviewsinlayout ();        Requestlayout ();        Invalidate (True);    }

Removeallviewsinlayout () and Removeallviews () have the ability to remove sub-view, but removeallviewsinlayout () needs to measure the current layout first, and once the method is called, You can only remove the included child view that has already been calculated in its own layout. In contrast, removeallviews () also calls Removeallviewsinlayout (), but later calls Requestlayout (), which is called when the layout of the view changes to update the current view. Removing a child view is more thorough. Therefore, it is recommended to use the Removeallviews () method unless necessary.





The difference between removeallviews () and Removeallviewsinlayout () in ViewGroup

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.