Android 在一个对话框中同时显示两个网络视图

Android 在一个对话框中同时显示两个网络视图,android,android-layout,android-webview,android-linearlayout,android-dialog,Android,Android Layout,Android Webview,Android Linearlayout,Android Dialog,我目前有一个WebView作为对话框的“contentView”。这很好用。 现在我想在一个对话框中并排显示两个Web视图 我尝试将它们放在一个LinearLayout中,并使用该LinearLayout作为对话框的“contentView”。但它不起作用 这是我的代码,结果只是一个空对话框(高度约为一行) 注:活动固定在横向模式 Dialog dialog = new Dialog(context); LinearLayout linearLayout = new

我目前有一个WebView作为对话框的“contentView”。这很好用。 现在我想在一个对话框中并排显示两个Web视图

我尝试将它们放在一个LinearLayout中,并使用该LinearLayout作为对话框的“contentView”。但它不起作用

这是我的代码,结果只是一个空对话框(高度约为一行) 注:活动固定在横向模式

Dialog dialog = new Dialog(context);           
    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    WebView webView1 = new WebView(this);
    webView1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 1));
    webView1.getSettings().setPluginsEnabled(true);
    webView1.getSettings().setJavaScriptEnabled(true);
    webView1.setBackgroundColor(Color.LTGRAY);
    webView1.loadUrl("http://www.url1.com");
    linearLayout.addView(webView1);

    WebView webView2 = new WebView(this);
    webView2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 1));
    webView2.getSettings().setPluginsEnabled(true);
    webView2.getSettings().setJavaScriptEnabled(true);
    webView2.setBackgroundColor(Color.LTGRAY);
    webView2.loadUrl("http://www.url2.com");
    linearLayout.addView(webView2);


    dialog.setContentView(linearLayout);
    dialog.show();

使用getApplicationContext而不是context来实例化对话框。这有时有效…

使用wrap\u内容作为线性布局的高度刚刚检查了代码。这对我有用。什么是
上下文
?它是通过打开此对话框的方法(ShowVerKeersInformation)传递的上下文。btnVerkerInfo.setOnClickListener(新的OnClickListener(){@Override public void onClick(视图v){showVerkeersinformate(SpeedMeterActivity.this);}});所以“SpeedMeterActivity.this”作为一个参数传递,在上面的代码中由“context”表示,我明白了。也许,我应该用“context”而不是“this”来实例化LinearLayout