Francis Francis - 1 month ago 17
Android Question

trying to make a webview take the entire screen

I am loading a web url without a web browser in my android application. So, I am trying to make a webview to fit the entire screen of the window but it not working. I have set the webview as fill_parent in the width and height but still not working. as shown:

<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>


then in my activity class I have this code as shown:

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);
}
}
});


Please how can I make the webview to take the entire screen of the window

Answer

You need to remove all these

    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 is a gap between the boundary and the content of that view so here the content is webview and boundary is your layout plus for best practice you should use match_parent instead of fill_parent