Too large to fit cache drawing in webview inside scrollview

I am working on a scrollview that contains a web view, it works fine on 2.3, 4.1, but when I try to use it in 4.4 emulator, it shows

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

Web browsing is simply empty.

And this 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 using mywebView.setDrawingCacheEnabled(false); but it just returns the same warning.

In addition, I found that the problem occurs when the web page has a screen size, but when I show it, I find that the layout of the web interface is slightly different, by 2.3, 4.1, it can just start a new line if this word exceed the page, but in 4.4 this is not so, so part of the word is off screen.

How to fix it? Thanks

+8
android webview scrollview
source share
3 answers

My suggestion gives the height of the layout for web browsing, so that it will not exceed the 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, simply include the following lines

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

Everything will be fine. any doubt let me know

+4
source share

I suggest you use your own WebView client. In android, we can use WebViewClient or WebChromeClient. Using this, you will get the best result you need. Just try and check.

+2
source share

For WebViews on Android, you should assume that errors do not work. They should not be, but, as you discovered, if you made the background flat color, it "solves" the problem.

Having said that, itโ€™s still worth bearing in mind that you are dealing with a wide range of mobile devices with completely different calculations and memory allocation when you encode Android phones, so always be sure to test on a real device.

If you do not have at least 4 or 5 different physical Android devices on which you can test, then look at services that will allow you to use their devices for remote testing. Never believe that since you tested something in the emulator, it will behave the same on a real device.

0
source share

All Articles