Android's Webview on xhdpi device

308 views
Skip to first unread message

Baptiste Augrain

unread,
Mar 5, 2014, 8:10:49 PM3/5/14
to phon...@googlegroups.com
Hello,

I've an application which works correctly under iOS and I'm porting it to Android.
But when I try to run it under Moto G, I have the following behaviours:
  • with <meta name="viewport" content="user-scalable=no, initial-scale=1, minimum-scale=1, maximum-scale=1, width=device-width"/>, the window size is only 360x567 and not 720x1134 like I would expected
  • with <meta name="viewport" content="user-scalable=no, initial-scale=0.5, minimum-scale=0.5, maximum-scale=0.5, width=device-width"/>, the window size is still 360x567 but the document size is 720x1134. But only 1/4 on the document is displayed, I need to scroll to see the rest of the the page.
  • with <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />, still 360x567
How can I have a window size of 720x1134?

On iOS retina, I use <meta name="viewport" content="user-scalable=no, initial-scale=0.5, minimum-scale=0.5, maximum-scale=0.5, width=device-width"/> which give me the window at the full size.

Thanks
Baptiste

chris van hooser

unread,
Mar 6, 2014, 12:14:48 AM3/6/14
to phon...@googlegroups.com
I was running into kind of the same issue. It seems the initial-scale seems like it is ignored in android, so what i did was set the initial-scale higher then the min scale, and everything then was at the right resolution.

This is how i setup my viewport:

var meta = document.createElement("meta");
    meta
.setAttribute('name','viewport');
    meta
.setAttribute('content','initial-scale=1.5,height=device-height,user-scalable=no, width=device-width,maximum-scale='+ (1/window.devicePixelRatio) + ',minimum-scale='+ (1/window.devicePixelRatio));
    document
.getElementsByTagName('head')[0].appendChild(meta);

Baptiste Augrain

unread,
Mar 6, 2014, 5:50:16 AM3/6/14
to phon...@googlegroups.com
It's working! Thanks a lot.
I wouldn't have thought that by setting the initial-scale to a wrong value, it would fix the problem.

chris van hooser

unread,
Mar 6, 2014, 11:55:48 AM3/6/14
to phon...@googlegroups.com
Me either, but with the remote debugger in Android 4.4 I changed the viewport in the chrome debugger and found that out.
Reply all
Reply to author
Forward
0 new messages