I am working on a scrollview that contain a webview, it works perfect on the 2.3, 4.1 , but when I try it on the 4.4 emulator, it show

  View too large to fit into drawing cache, needs 5744640 bytes, only 3932160 available

The webview is just blank.

And it is the layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:overScrollMode="never" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="5dp" >

            <TextView
                android:id="@+id/newsTitle"
                android:textSize="18sp"
                android:textStyle="bold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/last_update" />

            <WebView
                android:id="@+id/newsContent"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="@string/last_update" />

            <TextView
                android:id="@+id/newsDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/last_update" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>

I tried to use mywebView.setDrawingCacheEnabled(false); but it just return the same warning.

Also, I find the problem occur when the webpage is overscreen size , but when I show it , I find the layout of the web is slightly different, on 2.3 , 4.1 , it can simply start the new line if the word is exceed the page, however , in 4.4 it does not , so part of the word is out of the screen .

How to fix it? Thanks

有帮助吗?

解决方案

My Suggestion is give layout height to webview so that it wont exceed the your specified height

<LinearLayout
            android:id="@+id/webview1"
            android:layout_width="fill_parent"
            android:layout_height="150dip" >

            <WebView
                android:id="@+id/sampletxt"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>

In your activity just include the below lines

 SampleTxt.getSettings().setLoadWithOverviewMode(true);
                SampleTxt.getSettings().setJavaScriptEnabled(true);
    SampleTxt.loadData("Your Text To show the Webview",
                        "text/html; charset=UTF-8", null);

It will work fine. any doubts let me know

其他提示

I suggest you to use your own WebView client. In android we can use WebViewClient or WebChromeClient. Using this you would get better result that you want. Just try it and check.

For WebViews in Android, you should start from the assumption that things are buggy. They shouldn't be, but as you discovered, if you make the background a flat color, it "resolves" the issue.

Having said that, it is still a good idea to keep in mind that you're dealing with a wide range of mobile devices with wildly different processing and memory allocations when you're coding for Android phones, so always be sure to test on a real device.

If you don't have at least 4 or 5 different physical Android devices that you can test on, then look around for services that allow you to use their devices to test remotely. Never believe that because you have tested something in an emulator, it will behave the same on a real device.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top