使用viewpager时遇到的一个问题:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child’s parent first.
错误的意思是孩子已经有父母 需要使用removeView() 方法先从父母上移除才能使用add()方法。
那么怎么解决呢?
获取孩子的父母级 使用removeView
解决办法是在instantiateItem中使用如下方式:
ViewGroup parent = (ViewGroup) v.getParent();
if (parent != null) {
parent.removeAllViews();
}
container.addView(v);
1807

被折叠的 条评论
为什么被折叠?



