3

The Android doc says that getScale() method was deprecated.
I have implemented onScaleChanged(WebView, float, float) to get the new scale, but this method is triggered only when the scale is changed.
So, what is the default scale value for the webview?
From the getScale() method, it is 2.0f, but is this value always 2.0f on all devices?

phibao37
  • 2,230
  • 4
  • 26
  • 35

1 Answers1

3

According to the Developers WebView documentation, the scaling depends on the pixel density on the screen of the device:

By default, WebView scales a web page so that it is drawn at a size that matches the default appearance on a medium density screen. So, it applies 1.5x scaling on a high density screen (because its pixels are smaller) and 0.75x scaling on a low density screen (because its pixels are bigger). Starting with API level ECLAIR, WebView supports DOM, CSS, and meta tag features to help you (as a web developer) target screens with different screen densities.

Further information is found on the page Supporting Different Screens in Web Apps, where there is information (and sample code) to query the device density with JavaScript:

if (window.devicePixelRatio == 1.5) {
  alert("This is a high-density screen");
} else if (window.devicePixelRatio == 0.75) {
  alert("This is a low-density screen");
}
  • 2
    So, is there anyway to get the initial value from the code? – phibao37 May 16 '15 at 12:06
  • Am not entirely sure about that; however, there are ways to specify the scaling, which incidently only is 0.75, 1.0 and 1.5 for low, medium and high density screen devices. –  May 16 '15 at 12:12
  • @user2447581 I found some information (and code) that allows the specific scale factor used to be found. –  May 16 '15 at 12:27
  • Very late to the party... But look at this answer: https://stackoverflow.com/a/25787425/9625282 getResources().getDisplayMetrics().density should do the trick. – Brontes Jan 27 '21 at 13:05