Possible Duplicate:
Android Webview - Webpage sh开发者_StackOverflow社区ould 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!!
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.
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;
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
精彩评论