1

I have a WebView in which I wish to render some content. But this WebView does not show a single character if the length of data I am showing reaches close to 5100 characters.

The WebView works perfectly fine if the length of data is less than 5000 characters.

I have tried to just pass simple data in the WebView similar to "abcde ....." with < 5000 chars it would work fine. with > 5100 chars it won't display a single character.

I have searched through the Internet to see if there are any limits for the amount of data that can be shown inside the WebView, but I don't seem to find anything.

Here is my Java Code.

myWebView = (WebView) findViewById(R.id.passage);

String data = "abcde ......."; // large number of characters > 5100.

myWebView.loadDataWithBaseURL(URL, data, "text/html", null,null);

I have tried myWebView.loadData(data, "text/html", null); as well instead of using the loadDataWithBaseURL function, but that has not helped.

Here is the XML that I am using.

    <ScrollView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:fadeScrollbars="false"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:scrollbarFadeDuration="0" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingBottom="5dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:paddingTop="10dp" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/passage"
                android:textColor="@color/red"
                android:textSize="18px" />

            <WebView
                android:id="@+id/passage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fadeScrollbars="false"
                android:layerType="software"
                android:scrollbarAlwaysDrawVerticalTrack="true"
                android:scrollbarFadeDuration="0" />
        </LinearLayout>
    </ScrollView>

Please help.

EDIT : To be more precise, if I render 5096 characters, it renders properly. If 5097 or more characters are attempted to be rendered, then nothing gets displayed. If I try to log the data variable in a file. All data gets logged, so its not a issue relating to proper data not being saved into string.

4

1 回答 1

1

这发生在我身上,但 WebView 内容大小要小得多。通过加载 1506 个字符loadDataWithBaseURL工作得很好,但是当加载 1507 个字符时,整个 WebView 消失了,包括背景。(但我仍然可以从中复制文本。)

解决方法是删除android:layerType="software"并回退到默认的硬件 layerType。

于 2015-01-12T20:23:55.800 回答