java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
发生了上面的错误,原因很简单一个View不能有两个不同的parent。
saomiaoview = inflater.inflate(R.layout.sao_miao_child_menu, view, true);
saomiaochildLayout = (LinearLayout) saomiaoview.findViewById(R.id.child_layout);
((FrameLayout) rootview).addView(saomiaochildLayout);
主要由于第一句代码引起的,上面的inflate()函数已经将view作为saomiaoview的parent了。
而
((FrameLayout) rootview).addView(saomiaochildLayout);
这句代码由给saomiaoview添加了一个parent了。
解决方法:
((FrameLayout) rootview).removeAllViews();
((FrameLayout) rootview).addView(saomiaochildLayout);