下面是removeAllViewsInLayout()的源码
/** * Called by a ViewGroup subclass to remove child views from itself, * when it must first know its size on screen before it can calculate how many * child views it will render. An example is a Gallery or a ListView, which * may "have" 50 children, but actually only render the number of children * that can currently fit inside the object on screen. Do not call * this method unless you are extending ViewGroup and understand the * view measuring and layout pipeline. */ 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); } }
方法removeAllViews()的源码
/** * Call this method to remove all child views from the * ViewGroup. */ public void removeAllViews() { removeAllViewsInLayout(); requestLayout(); invalidate(true); }
ViewGroup中removeAllViews()和removeAllViewsInLayout()之间的区别
原文地址:http://blog.csdn.net/stzy00/article/details/43966149