0

I'm using an android's webview to display some html with javascript being executed when the DOM is ready; but screen.width gives the wrong value, unless I'm using some timeout before querying for it(on emulators and real devices)

The problem is with devices of high/low density. For example, a device of size 480 X 800 of high density will results in screen of 320 x 533 (it divides by 1.5 both screen width and height) and for screen of size 240x320 of low density it gives 320x426 (again, it divides by 0.75 both width and height).

When I apply some css and set the body's width to 100%, it flickers, since the body's width is being set to 320px and after half a second it is being set again, this time to the real size of 480px.

Using a timer to query the screen's width and height prior to applying some css is unacceptable, since on different devices, different time intervals are needed (300ms, 500ms) - How can I apply css with different screen sizes

emulators:

FWQVGA (240×432, low density, normal screen)
HVGA (320×480, medium density, normal screen)
WVGA800 (480×800, high density, normal screen)

Is there any solution to this problem?

2
  • I think I'm seeing the asme problem. Did you manage to find more info? Commented Mar 6, 2012 at 13:10
  • How do you judge the time of dom ready? Commented Oct 16, 2019 at 7:51

1 Answer 1

2

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).

You might read this: "Building web pages to support different screen" @ http://developer.android.com/reference/android/webkit/WebView.html

Sign up to request clarification or add additional context in comments.

1 Comment

Ah crap - sorry, I accidentally hit the wrong arrow. Had to make a minor edit to remove the error and do a +1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.