问题
in my app I have a webview, which should display a responsive website. The device width for showing the mobile version is limited by 767 px, so the smartphones with a 1280x720 resolution displays the mobile website correct.
When I now open the app on my s4 (resolution: 1920 x 1080) I expect the webview, to show the normal desktop website and it does. But when I open it in normal web browser like Chrome, the responsive layout is shown.
Can anyone explain that behaviour? Is it possible to also show the responsive website in my webview on the s4?
Webpage contains the following
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
Greetings, jennymo
回答1:
You can try writing this line of codes i am giving the example code if you didn't import javascript in your app first you need to enable javascript and then add these lines of code in the Android webview
WebSettings webSettings = mWebview.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
Try adding these lines it may help i tried and it works for me
回答2:
first of all, the s4 has a 1920 x 1080 resolution but this does not mean the screen is 1920 x 1080 pixels wide and high. samsung has a 3.0 device pixel density (http://bjango.com/articles/min-device-pixel-ratio/) and this means that 1 css px is 3px (read this for more information: http://www.quirksmode.org/blog/archives/2010/04/a_pixel_is_not.html) so you have to divide that number by 3 to get the CSS PIXEL unit which is: 640 x 360px.
this may be why you are not seeing what you expect to see on mobile/web browser
来源:https://stackoverflow.com/questions/23363441/android-responsive-website-is-shown-in-browser-but-not-in-webview