WebView不能在带有CollapsibleToolBarLayout的NestedScrollView中滚动

问题描述 投票:0回答:1

我目前有这样的布局设置:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:elevation="4dp">
        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/android_icon"
                app:layout_collapseMode="parallax" />
            <androidx.appcompat.widget.Toolbar
                android:id="@+id/generic_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:fitsSystemWindows="true"
                android:background="@null"
                app:layout_collapseMode="pin"/>
        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>
    <androidx.core.widget.NestedScrollView
        android:id="@+id/primary_nestedScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <WebView
            android:id="@+id/primary_webview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

虽然这在大多数情况下都可以正常工作,但是当我要确保其内容充满视口时,Web视图的滚动存在问题。

如果将android:fillViewport="true"属性添加到NestedScrollView,则视口将正确填充,并且折叠的工具栏仍会折叠,但是Webview本身无法再滚动。

我已经在一个小样的演示项目视频中对此进行了演示:https://i.imgur.com/EJevXuz.mp4

((编辑:似乎录音中有一些闪烁的伪像。这是录音问题,与问题无关)

您可以看到,当fillViewPort设置为false时,滚动效果很好。尽管符合预期,但内容(具有深灰色背景)如果太短/太小,则不会填充可用空间。

[当NestedScrollView上的fillViewPort值设置为true时,内容(的背景)确实会填充可用空间,但是在较大内容上的任何滚动似乎都被禁用(WebView在其顶部滚动位置“卡住”了)尽管Web视图中的滚动条指示有更多内容可用。

我已经尝试了很多方法来使它再次起作用(包括在网络上找到的几个NestedWebView实现),但到目前为止没有任何效果。

如何通过fillViewPort选项在此布局设置中再次正确滚动来获取WebView?

android webview android-collapsingtoolbarlayout android-nestedscrollview coordinator-layout
1个回答
0
投票

我终于找到了适合我情况的NestedWebView实现。

© www.soinside.com 2019 - 2024. All rights reserved.