Java – Android WebView, zooming content to fit the screen

My friend created an application using JavaScript and uploaded it to his website

Now I'm trying to wrap it in WebView in Android, which works well in some ways

This page is 480 × three hundred and twenty

But no matter what screen I choose on Android, there is a blank area at the bottom of WebView I've tried many ways to scale it, but there's no effect

My code at this time is like this

final WebView browser = (WebView)findViewById(R.id.webview);   
    browser.getSettings().setJavaScriptEnabled(true);
    browser.loadUrl("http://page.xx");

Solution

wb.loadUrl("javascript:document.body.style.zoom = "+String.valueOf(scale)+";");
wb.loadUrl("javascript:document.body.style.zoom = "+String.valueOf(scale)+";");

Where scale is a floating point number that you can calculate - I think you need something like this in your case: browser getHeight()/ 480dp. Load this URL after the page is loaded

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>