13

Possible Duplicate:
Android Webview - Webpage should fit the device screen

I want to render a webpage in android's webview. Currently, I can display a webpage but how to make it fit within the screen? I referred to: Android Webview - Webpage should fit the device screen but didn't find a solution there.

Thanks!!

Community
  • 1
  • 1
cooltechnomax
  • 681
  • 3
  • 10
  • 21
  • Its not a duplicate, because the guy already said he checked that question and didn't find a solution... – Richard Le Mesurier Apr 18 '13 at 13:42
  • It would have helped if the OP had said _why_ @Richard. This question may not be a duplicate but there's absolutely no information to enable anyone to answer it. It should remain closed. – Ben Apr 18 '13 at 14:00

3 Answers3

29

The only way that works for me was this way:

webView = (WebView) findViewById(R.id.noticiasWebView);
webView.setInitialScale(1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webView.loadUrl("http://www.resource.com.br/");

I am working on Android 2.1 because of the kind of devices from the company. But I fixed my problem using the part of informations from each one.

Bart
  • 19,692
  • 7
  • 68
  • 77
Josmar Peixe
  • 691
  • 7
  • 4
8

My solution was different. I made a webpage big enough so it would then get zoomed out. And in the webview settings i put the following:

WebView webview = new WebView(this);
//webview.setInitialScale(100); No need for this one
WebSettings settings = webview.getSettings();
settings.setBuiltInZoomControls(false);
settings.setUseWideViewPort(true);
settings.setJavaScriptEnabled(true);
settings.setSupportMultipleWindows(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setLoadsImagesAutomatically(true);
settings.setLightTouchEnabled(true);
settings.setDomStorageEnabled(true);
settings.setLoadWithOverviewMode(true);

Be sure to import the following: import android.webkit.WebSettings.ZoomDensity;

Justin
  • 84,773
  • 49
  • 224
  • 367
John Starkin
  • 91
  • 1
  • 4
  • Forgot to say that you must delete the **viewport metatag** in your HTML for this to work. – John Starkin Nov 22 '11 at 15:56
  • Sounds interesting, I have just tested your answer with my web view implementation, it simply works. Why do not work with viewport metatag, viewport is created for mobile device compatibility? Many Thanks. – burakim Jul 08 '15 at 07:04
4

Your question is not very clear but if I'm guessing you mean the webview is not expanding to fit the whole screen? Please post your code to support your question.

To make the webview expand to the whole screen, add the webview in your activity layout xml and make sure you set the layout_width and layout_height to fill_parent. Here's a simple example:

  <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
      <WebView  
          android:id="@+id/webview"
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent"/>
  </LinearLayout>

Ryan

Ryan
  • 1,797
  • 12
  • 19
  • I already have a webview with "fill_parent", what I want is the webpage I am loading in a webview should fit exactly in that webview without scrollbars. And later the user should be able to zoom in and zoom out to view the content of webpage. – cooltechnomax Jun 15 '11 at 20:19
  • 1
    Take a look at this answer by Brian, might be what you're looking for. http://stackoverflow.com/questions/3808532/how-to-set-the-initial-zoom-width-for-a-webview – Ryan Jun 16 '11 at 14:57