안녕하세요.
구글 검색과 스택오버플로우에도 답을 찾지 못해 질문을 올립니다.
webview를 사용하여 어플을 구동하고 있습니다.
당연 window.open()의 호출도 있기에 부모 webview의 setWebChromeClient를 사용하여 child webview를 생성해서 popup을 제어하고 있습니다.
그런데 부모 webview를 아래쪽으로 스크롤 하여 window.open()을 호출하면 child webview가 부모 webview의 상단에 위치하여 노출됩니다.
부모 webview를 위아래로 스크롤 하더라도 child webview가 화면의 중앙에 꽉차도록 해서 노출시키려고 하는데 제가 작성한 코드 외에 다른 방법이 있나요?
그림으로 보면 아래와 같습니다.
왼쪽이 현재의 문제고 오른쪽으로 수정하고 싶습니다.

그리고 저 child webview에 layout.xml 을 직접 설정할수 있나요?
childe webview가 나올때는 하단에 닫기버튼을 만들려고 합니다.
child webview 생성시에 findViewbyId가 아닌 new로 생성해서 방법을 못찾겠네요.
제가 작성한 소스입니다.
-- java
webView.setWebChromeClient(new MyWebChromeClient());
private class MyWebChromeClient extends WebChromeClient {
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
webView.removeAllViews();
childView = new WebView(MainActivity.this);
childView.getSettings().setJavaScriptEnabled(true);
childView.setWebChromeClient(this);
webView.addView(childView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(childView);
resultMsg.sendToTarget();
return true;
}
}
}
-- activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="@+id/activity_closebutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#fff"
android:text="닫기"
android:textSize="14.0dip"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>