Can't get Dialog hosting a WebView to layout properly
Posted
by user246114
on Stack Overflow
See other posts from Stack Overflow
or by user246114
Published on 2010-06-15T18:29:27Z
Indexed on
2010/06/15
18:32 UTC
Read the original article
Hit count: 184
android
Hi,
I'm trying to host a webview on a dialog, without a titlebar, but I'm getting odd layout results. Example test:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
LinearLayout ll = new LinearLayout(getContext());
ll.setOrientation(LinearLayout.VERTICAL);
ll.setLayoutParams(new LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));
ll.setMinimumWidth(display.getWidth() - 10);
ll.setMinimumHeight(display.getHeight() - 10);
WebView wv = new WebView(getContext());
wv.setLayoutParams(new LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));
wv.getSettings().setJavaScriptEnabled(true);
ll.addView(mWebView);
setContentView(ll, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));
}
the dialog is inflated at startup, but the webview is not visible. If I rotate the device, it becomes visible, and fills the whole parent layout as requested.
What is the right way to do this? I simply want a dialog which occupies most of the device screen, and has a WebView on it which fills the entire space.
Thanks
© Stack Overflow or respective owner