代码:
@Override
public Object instantiateItem(View view, int position) {
View myView = views.get(position);
myView.invalidate();
((ViewPager) view).removeView(myView);
((ViewPager) view).addView(myView); //Causing Error
return myView;
}
错误日志:
com.testapp.main fatal error : The specified child already has a parent.
You must call removeView() on the child's parent first.
java.lang.IllegalStateException: The specified child already has a parent.
You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:3378)
at android.view.ViewGroup.addView(ViewGroup.java:3249)
at android.support.v4.view.ViewPager.addView(ViewPager.java:1243)
at android.view.ViewGroup.addView(ViewGroup.java:3194)
at android.view.ViewGroup.addView(ViewGroup.java:3170)
我在添加子视图之前调用removeView()
然后出现错误原因?