Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView viewport

With html below I expected that the green rectangle would occupy only half of the screen, but in practice it occupies the whole screen width. I tried other values for viewport width, no luck. Any ideas why it does not work?

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>
like image 752
alex2k8 Avatar asked Dec 23 '10 00:12

alex2k8


1 Answers

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

WebSettings settings = webView.getSettings();
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
like image 135
AlexKorovyansky Avatar answered Sep 20 '22 10:09

AlexKorovyansky