简体   繁体   中英

Data inside the webview fit to screen height and width

I have html text shown in below link http://pastebin.com/KVTUnhXL My issue is when I try to load it in webview it looks very small. My requirement is by default it should occupy device height and width so that it looks proper below is my code

        mWebView.getSettings().setJavaScriptEnabled(true);

        mWebView.getSettings().setLoadWithOverviewMode(true);
        mWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
        mWebView.getSettings().setBuiltInZoomControls(true);

        mWebView.getSettings().setUseWideViewPort(true);
        mWebView.loadData(content, "text/html; charset=UTF-8", null);

Please help.

Below is my layout file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="@drawable/bg_general">


    <WebView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent" />



</RelativeLayout>

This is a simple one:

To set the HTML to use the full Viewport :

<meta name="viewport" content="width=device-width, initial-scale=1">

in the HTML body tag.

To remove margin and padding from HTML Page:

CSS:

body {
    margin: 0;
    padding: 0;
}

If you load content from a remote webserver use a HTML Processing Library such as JSOUP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM