webview中的数据适合屏幕高度和宽度

时间:2015-11-25 12:59:30

标签: android html webview

我在下面的链接中显示了html文字 http://pastebin.com/KVTUnhXL 我的问题是,当我尝试在webview中加载它时,它看起来非常小。我的要求是默认它应该占用设备的高度和宽度,以使它看起来正确 下面是我的代码

        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);

请帮忙。

以下是我的布局文件

<?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>

1 个答案:

答案 0 :(得分:2)

这很简单:

设置HTML以使用完整的视口

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

在HTML正文标记中。

从HTML页面删除边距和填充:

CSS:

body {
    margin: 0;
    padding: 0;
}

如果您从远程网络服务器加载内容,请使用HTML处理库,例如JSOUP

相关问题