我收到"java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first android"
以下代码的错误。
从日志中可以看出该行中出现了错误。setContentView(mWebPageParentView)
在 public void onHideCustomView()
API 中。
请帮助我尽早解决这个问题。
//初始声明。
private WebChromeClient mWebChromeClient = null;
private View mFullScreenVideoView;
private RelativeLayout mWebPageParentView;
private FrameLayout mFullScreenViewContainer = null;
private WebChromeClient.CustomViewCallback mFullScreenVideoViewCallback;
// 代码
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
if (mFullScreenVideoView != null) {
callback.onCustomViewHidden();
return;
}
// The below line was missing while writing here.
mWebPageParentView = (RelativeLayout) findViewById(R.id.lyt_main);
// The above line was missing while writing here.
mWebPageParentView.setVisibility(View.GONE);
mFullScreenViewContainer = new FrameLayout(BrowserActivity.this);
mFullScreenViewContainer.setLayoutParams(LayoutParameters);
view.setLayoutParams(LayoutParameters);
mFullScreenViewContainer.addView(view);
mFullScreenVideoView = view;
mFullScreenVideoViewCallback = callback;
mFullScreenViewContainer.setVisibility(View.VISIBLE);
setContentView(mFullScreenViewContainer);
}
@Override
public void onHideCustomView() {
if (mFullScreenVideoView == null) {
return;
} else {
// Hide the custom view.
mFullScreenVideoView.setVisibility(View.GONE);
mFullScreenViewContainer.removeView(mFullScreenVideoView);
mFullScreenViewContainer.setVisibility(View.GONE);
mFullScreenViewContainer = null;
mFullScreenVideoViewCallback.onCustomViewHidden();
// Show the content view.
mWebPageParentView.setVisibility(View.VISIBLE);
setContentView(mWebPageParentView);
}
}