滚动recyclelerview项目期间隐藏Android webview内容

时间:2017-07-20 16:39:38

标签: android webview

我想在一些RecyclerView项目中使用简单的WebView,我从源代码生成html并将其附加到webview中,例如:

String page = SourceUtils.generateContent("\nthis is test\nimport java.fx;\nimport android;\nprint(\"my name is mahdi\");\n", "github-gist", null, false, true);

holder.webview.getSettings().setJavaScriptEnabled(true);
holder.webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
holder.webview.loadDataWithBaseURL("file:///android_asset/", page, "text/html", "utf-8", null);

到目前为止一切正常,现在我正在滚动recyclelerview项目,例如向上或向下,导致隐藏webview生成的html内容

生成的html结果是:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <style type="text/css">
        html, body {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }
    </style>
    <link rel="stylesheet" href="./styles/github-gist.css">
    <style type="text/css">
        .hljs-line-numbers {
            text-align: right;
            border-right: 1px solid #ccc;
            color: #999;
            -webkit-touch-callout: none;
            -webkit-user-select: none;
            -khtml-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }
    </style>
    <script src="./highlight.pack.js"></script>
    <script src="./highlightjs-line-numbers.min.js"></script>
    <script>hljs.initHighlightingOnLoad();</script>
    <script>hljs.initLineNumbersOnLoad();</script>
</head>
<body style="margin: 0; padding: 0">
<pre>
    <code>
    this is test
    import java.fx;
    import android;
    print("my name is mahdi");
</code></pre>
</body>
</html>

我的xml布局是:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    android:minHeight="300dp"
    card_view:cardBackgroundColor="@color/transparent_white"
    card_view:cardCornerRadius="2dp"
    card_view:cardElevation="1dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <WebView
            android:id="@+id/plainTextPostContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"/>

    </LinearLayout>


</android.support.v7.widget.CardView>

0 个答案:

没有答案