如何同时使用NestedScrollView、SwipeRefreshLayout和WebView?

3

使用最新的库。我有一个简单的WebView在CoordinatorLayout片段中。试图在用户向下滚动时隐藏工具栏。

<android.support.design.widget.CoordinatorLayout       

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/clRootHome"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.bytefury.deliverzz.fragment.HomeFragment">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_scrollFlags="scroll|enterAlways"
    android:theme="@style/AppTheme.AppBarOverlay">

    <include layout="@layout/toolbar" />

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/srlHome"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

         <im.delight.android.webview.AdvancedWebView
            android:id="@+id/frag_wv_wv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbarStyle="insideOverlay" />

</android.support.v4.widget.NestedScrollView>

</android.support.v4.widget.SwipeRefreshLayout>



</android.support.design.widget.CoordinatorLayout>

然而,这根本没有任何作用。下拉刷新功能正常。

情急之下,当我将NestedScrollView和SwipeRefreshLayout交换位置时,屏幕变成了一片空白。


1
我认为你不需要在那里使用NestedScrollView。WebView应该可以很好地处理滚动。 - Bubunyo Nyavor
我可能没有表达清楚。NestedScrollView被用来在webView滚动时隐藏工具栏。 - jpf
你可以不使用NestedScrollView来实现。我会发布一个答案。 - Bubunyo Nyavor
1个回答

0
如果您想让您的工具栏可滚动,请将您的布局重构为以下内容。
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/clRootHome"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.bytefury.deliverzz.fragment.HomeFragment">

        <include layout="@layout/toolbar" />

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/srlHome"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

         <im.delight.android.webview.AdvancedWebView
            android:id="@+id/frag_wv_wv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbarStyle="insideOverlay" />

     </android.support.v4.widget.SwipeRefreshLayout>

现在将其添加到您的工具栏布局中。

        app:layout_scrollFlags="scroll|enterAlways"

3
回答问题时,尽量让它对未来的访问者有用,而不仅仅是对作者有用。同时,更清晰地说明您所添加的内容,不要只给出代码。 - Ali Bdeir

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接