>我正在将嵌套滚动视图添加到Web视图,以便在用户滚动时隐藏/显示工具栏。该活动工作正常,直到我添加了嵌套滚动视图可以进行隐藏/显示移动。在这一刻,我收到一个错误,我不知道如何解决它。
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
可以自行滚动。没有必要将其放在 NestedScrollView
.这样做可能会减小 Web 视图的大小。不用担心app:layout_behavior="@string/appbar_scrolling_view_behavior"
,它也应该适用于WebView
(尽管有些边缘情况可能难以设置(。例如
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
android:id="@+id/webview_browser"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<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>
如果这不起作用,请查看 WebView 的父项。其中一个可能太大(=它的高度(。所以尽量不要超过屏幕的高度