Android 6 WebView内存不足

Android 6 WebView内存不足,android,webview,scrollview,android-6.0-marshmallow,Android,Webview,Scrollview,Android 6.0 Marshmallow,我遇到了一个问题,一切都很好。但现在我发现了这些错误: W/art: Throwing OutOfMemoryError "Failed to allocate a 61819212 byte allocation with 4032304 free bytes and 3MB until OOM" W/JavaBrowserViewRendererHelper: Error allocating bitmap E/chromium: [ERROR:java_browser_v

我遇到了一个问题,一切都很好。但现在我发现了这些错误:

W/art: Throwing OutOfMemoryError "Failed to allocate a 61819212 byte allocation with 4032304 free bytes and 3MB until OOM"     
W/JavaBrowserViewRendererHelper: Error allocating bitmap    
E/chromium: [ERROR:java_browser_view_renderer_helper.cc(133)] Error unlocking java bitmap pixels.
并且WebView未显示。这是我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/post_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffffff">

<ScrollView
    android:id="@+id/scrollview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:fillViewport="false"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:scrollbars="vertical"
    android:touchscreenBlocksFocus="false">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical"
        android:touchscreenBlocksFocus="false">

        <ImageView
            android:id="@+id/icon"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            android:src="@drawable/placeholder" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="left|top"
            android:layout_marginBottom="30dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="30dp"
            android:gravity="center|center_horizontal"
            android:text="Title"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <WebView
            android:id="@+id/webView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@+id/textView"
            android:clickable="true"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:scrollbars="none" />

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_gravity="center" />

        <ImageView
            android:id="@+id/nextprev"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="30dp"
            android:adjustViewBounds="true"
            android:src="@drawable/nextprev" />
    </LinearLayout>
</ScrollView>

正如您所看到的,WebView在ScrollView中,因为我希望WebView上下的视图能够滚动。我也尝试过从这里不使用ScrollView的解决方案,WebView加载得很好,但上面的内容都会滚动出来,但会留下空白覆盖WebView


我不知道,也许这只是我的错?无论如何,我很想知道是什么导致了这一点,以及如何解决它

我认为您已经解决了这个问题,但为了回答您的问题,您的模拟器内存不足

我在管理图像时也遇到同样的问题,因此我认为你可以减少应用程序中的图像数量。此外,如果您想正确管理它们,我建议您观看此视频


如果我错了,请更正。

切换到loadDataWithBaseURL,它不需要url编码器编码url,也不会在历史记录中保留大量数据url。这似乎已经修复了高cpu使用率和内存泄漏,以及安全性错误:WebView.loadDataWithBaseURL(url,data,“text/html”,“UTF-8”,url);我已经在使用它了。是的,这是模拟器的问题,它在设备上运行良好。您的视频不适用于WebView,因此在这种情况下它不是解决方案。无论如何,我通过将WebView移出ScrollView解决了这个问题。