0
votes

i have an url which has in the html body the following style:

  style='width:468px; height:60px;'

I want to add the url in a webview but its content is to big (witdh and height) so i have to resize both. I tried these solutions(Android Webview - Webpage should fit the device screen, http://developer.android.com/guide/webapps/targeting.html) and no one worked for me. I managed to change the width using:

 String javascript = "javascript:document.getElementsByTagName('div')[0].style.width='100%';";
 view.loadUrl(javascript);

but it does not work with the height beucase the content is too big. Do you know other ways to do this?

1

1 Answers

1
votes

finally i changed the sizes by using the following method:

    @Override
    public void onPageFinished(WebView view, String url) {
        float scale = myWebView.getHeight() / 170f;
        myWebView.setInitialScale((int) (scale * 100f));
        String js = "javascript:(function(){"
                + "document.getElementsByTagName('div')[0].style.height = 'auto';"
                + "document.getElementsByTagName('div')[0].style.width = 'auto';"
                + "})()";
        view.loadUrl(js);
    }