問題說明:java
View 在屢次調用view.getParent().removeView(view); 以後,調用ViewGroup.addView(view ) 程序崩潰。動畫
if (child.getParent() != null) { throw new IllegalStateException("The specified child already has a parent. " + "You must call removeView() on the child's parent first."); }
跟蹤ViewGroup.removeView() 咱們發現, 最終會調用到這個位置:this
private void removeFromArray(int index) { final View[] children = mChildren; if (!(mTransitioningViews != null && mTransitioningViews.contains(children[index]))) { children[index].mParent = null; }
由於被移除的視圖在mTransitioningViews中,(正在執行移除動畫)所以沒有將他的parent 設置爲空。 而後致使添加view 的時候,崩潰了。code
經過分析,找到了致使問題的緣由。ci
public void startViewTransition(View view) { if (view.mParent == this) { if (mTransitioningViews == null) { mTransitioningViews = new ArrayList<View>(); } mTransitioningViews.add(view); } }