lolyoshi
lolyoshi

Reputation: 1536

WebView.setInitialScale is not working

I load a content in the webview. At this time, I want the content to fit with the screen size that I don't need to scroll. However, the function setInitialScale() is not working. Can you tell me what's the problem in my code?

public class WebViewActivity extends Activity {

    private static WebView webView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);

        webView = (WebView) findViewById(R.id.webView1);
        webView.getSettings().setSupportZoom(true);
        webView.loadUrl("http://developer.android.com/reference/packages.html");


        webView.setWebViewClient(new WebViewClient() {

            public void onPageFinished(WebView view, String url) {

                webView.setPadding(0, 0, 0, 0);
                webView.setInitialScale(100); // here is the problem
        });
    }
}

Upvotes: 2

Views: 7950

Answers (1)

Md Abdul Gafur
Md Abdul Gafur

Reputation: 6201

You can use this to fixes size based on screen size.

WebView browser = (WebView) findViewById(R.id.webview);
browser.getSettings().setLoadWithOverviewMode(true);
browser.getSettings().setUseWideViewPort(true);

Upvotes: 3

Related Questions