【发布时间】:2014-04-05 20:50:15
【问题描述】:
在布局中添加视图以及删除和重新添加时,它会像这样抛出。
The specified child already has a parent. You must call removeView() on the child's parent first
有什么想法???
linearLayout.addView(view);
此行经常被调用(即每次活动恢复时), 所以我添加了这样的:
((ViewGroup)view.getParent()).removeAllViewsInLayout();
linearLayout.removeView(view);
if(linearLayout.getChildCount()==0)
linearLayout.addView(view);
但同样的问题!
【问题讨论】:
-
以适当的方式编辑您的问题,提供更多信息以及您迄今为止尝试过的代码示例,以避免无限 -ve 投票。
-
linearLayout.addView(view);这条线经常被调用(每次活动恢复时),所以我添加了类似 ((ViewGroup)view.getParent()).removeAllViewsInLayout();线性布局.removeView(view); if(linearLayout.getChildCount()==0) linearLayout.addView(view);
标签: android layout view android-linearlayout android-relativelayout