Java 试图使webview占据整个屏幕

Java 试图使webview占据整个屏幕,java,android,webview,Java,Android,Webview,我在android应用程序中加载一个没有web浏览器的web url。因此,我试图制作一个网络视图,以适应整个窗口的屏幕,但它不工作。我已将webview的宽度和高度设置为fill_parent,但仍不起作用。如图所示: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" andro

我在android应用程序中加载一个没有web浏览器的web url。因此,我试图制作一个网络视图,以适应整个窗口的屏幕,但它不工作。我已将webview的宽度和高度设置为fill_parent,但仍不起作用。如图所示:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >


    <WebView  
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
                                        />

    <ProgressBar
        android:id="@+id/prog1"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:padding="2dip" />

</RelativeLayout>
final ProgressBar Pbar;
        //final TextView txtview = (TextView)findViewById(R.id.tV1);
        Pbar = (ProgressBar) findViewById(R.id.prog1);

        getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);

        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setLoadWithOverviewMode(true);
        mWebView.getSettings().setUseWideViewPort(true);
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mWebView.loadUrl("http://unitytimes.com");
        mWebView.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });

        mWebView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                if (progress < 100 && Pbar.getVisibility() == ProgressBar.GONE) {
                    Pbar.setVisibility(ProgressBar.VISIBLE);
                    //txtview.setVisibility(View.VISIBLE);
                }
                Pbar.setProgress(progress);
                if (progress == 100) {
                    Pbar.setVisibility(ProgressBar.GONE);
                    //txtview.setVisibility(View.GONE);
                }
            }
        });

然后在我的活动类中,我有如下代码:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >


    <WebView  
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
                                        />

    <ProgressBar
        android:id="@+id/prog1"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:padding="2dip" />

</RelativeLayout>
final ProgressBar Pbar;
        //final TextView txtview = (TextView)findViewById(R.id.tV1);
        Pbar = (ProgressBar) findViewById(R.id.prog1);

        getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);

        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setLoadWithOverviewMode(true);
        mWebView.getSettings().setUseWideViewPort(true);
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mWebView.loadUrl("http://unitytimes.com");
        mWebView.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });

        mWebView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                if (progress < 100 && Pbar.getVisibility() == ProgressBar.GONE) {
                    Pbar.setVisibility(ProgressBar.VISIBLE);
                    //txtview.setVisibility(View.VISIBLE);
                }
                Pbar.setProgress(progress);
                if (progress == 100) {
                    Pbar.setVisibility(ProgressBar.GONE);
                    //txtview.setVisibility(View.GONE);
                }
            }
        });
最终进度条Pbar;
//最终文本视图txtview=(文本视图)findViewById(R.id.tV1);
Pbar=(ProgressBar)findviewbyd(R.id.prog1);
getWindow().setFeatureInt(Window.FEATURE\u进度,Window.PROGRESS\u可见性\u打开);
mWebView=(WebView)findViewById(R.id.WebView);
mWebView.getSettings().SetLoadWithOverview模式(true);
mWebView.getSettings().setUseWideViewPort(true);
WebSettings WebSettings=mWebView.getSettings();
setJavaScriptEnabled(true);
mWebView.loadUrl(“http://unitytimes.com");
setWebViewClient(新的WebViewClient()){
公共布尔值shouldOverrideUrlLoading(WebView视图,字符串url){
view.loadUrl(url);
返回true;
}
});
mWebView.setWebChromeClient(新WebChromeClient(){
public void onProgressChanged(WebView视图,int-progress){
if(进度<100&&Pbar.getVisibility()==ProgressBar.GONE){
Pbar.setVisibility(ProgressBar.VISIBLE);
//txtview.setVisibility(View.VISIBLE);
}
Pbar.setProgress(进度);
如果(进度==100){
Pbar.setVisibility(ProgressBar.GONE);
//txtview.setVisibility(View.GONE);
}
}
});

请问如何使webview占据窗口的整个屏幕

您需要删除所有这些

    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"

padding
是边界和该视图内容之间的间隙,因此这里的内容是
webview
,边界是您的布局加上最佳实践,您应该使用
match\u parent
而不是
fill\u parent

什么是webview的父布局代码?已经显示了整个xml文件。如果我没有弄错的话,它没有父布局“但它不工作”你是什么意思?请原谅我的措辞!我的意思是不要把整个屏幕的设备