Android WebView Viewer

In the html below, I expected the green rectangle to occupy only half the screen, but in practice it occupies the entire width of the screen. I tried other values ​​for viewport width, no luck. Any ideas why this is not working?

Html

<html> <head> <meta name="viewport" content="width=640" /> </head> <body> <div style="width: 300px; height: 50px; background: green;">300px</div> <div style="width: 600px; height: 50px; background: yellow;">600px</div> </body> </html> 

Xml

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <WebView android:id="@+id/web_view" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> 
+6
android width webview viewport
source share
2 answers

I had the same question and found the answer!
In your case, you need:

 WebSettings settings = webView.getSettings(); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); 
+13
source share

Partially resolved, now I can scale with a double click:

 webView.getSettings().setUseWideViewPort(true); 

EDIT: No, I was wrong ... I changed the test html and found that it scales to a page width of 1000 pixels, and not the width of the viewport to 640 pixels.

 <div style="width: 300px; height: 50px; background: green;">300px</div> <div style="width: 600px; height: 50px; background: yellow;">600px</div> <div style="width: 1000px; height: 50px; background: red;">1000px</div> 
0
source share

All Articles