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