Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fit a webpage on android screen(webview)? [duplicate]

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

like image 906
cooltechnomax Avatar asked Jun 14 '11 21:06

cooltechnomax


People also ask

How do I change the page to fit the screen on my Android?

* Open the Internet/Browser app. * Tap the menu button and choose Settings from the list. * Tap on the option Advanced. * Find the Auto-fit pages – Format Web pages to fit the screen option and make sure that this is checked.

How do I zoom out in WebView Android?

getSettings(). setBuiltInZoomControls(true); per this answer to default my view to zoomed out and to be able to pinch-to-zoom.

What is the WebView layout on Android?

The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout. It does not include any features of a fully developed web browser, such as navigation controls or an address bar. All that WebView does, by default, is show a web page.


2 Answers

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.

like image 114
Josmar Peixe Avatar answered Sep 28 '22 06:09

Josmar Peixe


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;

like image 43
John Starkin Avatar answered Sep 28 '22 07:09

John Starkin