【发布时间】:2019-06-10 14:50:48
【问题描述】:
我正在将 NestedscrollView 添加到 web 视图中,以便在用户滚动时隐藏/显示工具栏。在我添加 NestedScrollView 以进行隐藏/显示移动之前,该活动运行良好。在这一刻,我遇到了一个错误,我不知道如何解决它。
java.lang.IllegalStateException: Unable to create layer for WebView, size 720x12996 exceeds max size 8192
这是我的xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="@+id/ly_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/background_light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="@color/negro">
</RelativeLayout>
<include layout="@layout/generic_toolbar_browser" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<WebView
android:id="@+id/webview_browser"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.core.widget.NestedScrollView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_web_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone"
android:layout_marginTop="@dimen/margin_standard"/>
</RelativeLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Generic_toolbar_browser
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/home_appbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_browser"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:layout_collapseMode="pin"
app:titleTextColor="@color/white"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:layout_scrollFlags="scroll|enterAlways"
android:background="@color/blanco">
.....
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
【问题讨论】:
-
问题出在我活动中的这一行。删除后,一切正常 webview_browser.setLayerType(View.LAYER_TYPE_HARDWARE, null)
-
我也遇到了同样的错误,在我的情况下,
ScrollView中有WebView,我想停止滚动WebView,所以我在 WebView 中使用了这个android:scrollbars="none"。 它是否适合我?请帮忙
标签: android webview android-webview android-nestedscrollview