二、The specified child already has a parent. You must call removeView() on the child's parent first.

我写了一个应用程序,需要竖屏和横屏显示不同的布局

if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
	setNormalHorizontalView();
} 
else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
	setNormalVerticalView();
}
在竖屏时会使用ActivityManager进行视图切换

mFrameLayout.removeAllViews();
switch(mPresentActivity){
	case 0:
		mFrameLayout.addView((mLocalActivityManager.startActivity("", new Intent(GinwaveIMusic.this,GinwavePlayer.class)).getDecorView()));
		break;
	case 1:
		mFrameLayout.addView((mLocalActivityManager.startActivity("", new Intent(GinwaveIMusic.this,Album.class)).getDecorView()));
		break;
	case 2:
		mFrameLayout.addView((mLocalActivityManager.startActivity("", new Intent(GinwaveIMusic.this,GinwaveMusic.class)).getDecorView()));
		break;
	case 3:
		mFrameLayout.addView((mLocalActivityManager.startActivity("", new Intent(GinwaveIMusic.this,PlayList.class)).getDecorView()));
		break;
}
从竖屏切换到横屏然后再切换到竖屏时会出现The specified child already has a parent. You must call removeView() on the child's parent first.的bug,我按照提示已经添加了mFameLayout.removeAllViews()函数,但还是会出现这个问题,我想可能是由于在竖屏时已经执行过mLocalActivityManager.startActivity("", new Intent(GinwaveIMusic.this,GinwavePlayer.class)).getDecorView()方法,从横屏转换到竖屏后又会执行这个方法,而第一次切换后并没有进行对这个View进行释放,所以我在由竖屏切换到横屏时对这个View进行释放,我在onConfiguration中增加了以下代码后就没有问题了

if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
	if(mFrameLayout != null){
		mFrameLayout.removeAllViews();
	}
	setNormalHorizontalView();
} 




你可能感兴趣的:(二、The specified child already has a parent. You must call removeView() on the child's parent first.)