【问题标题】:How to use NestedScrollView, SwipeRefreshLayout and WebView together?如何同时使用 NestedScrollView、SwipeRefreshLayout 和 WebView?
【发布时间】:2016-08-30 15:32:54
【问题描述】:

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

<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 时,我得到一个空白的白色屏幕。

【问题讨论】:

  • 我认为你不需要NestedScrollView。 webview 应该可以很好地处理滚动。
  • 我可能不清楚。使用了 NestedScrollView,因此当 webView 滚动时工具栏将隐藏。
  • 您可以在没有NestedScrollView 的情况下实现这一目标。我会发布一个答案。

标签: android webview


【解决方案1】:

如果您希望您的工具栏可滚动,请将您的布局重构为此

<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"

【讨论】:

  • 当你回答一个问题时,试着让它对未来的访问者有用,而不仅仅是对作者。还要更清楚你添加的内容,不要只给他代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-30
  • 1970-01-01
相关资源
最近更新 更多