Swiperefresh layout not working in coordinate layout inside nested scrollview

I want to hide the toolbar when scrolling down so I use coordinate layout and that layout I need to use webview. when I use swiperefreshlayout inside nestedscrollview my webview doesn’t show up. How can I solve this problem?

Here is the layout file:

<?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"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".WebActivity">       <com.google.android.material.appbar.AppBarLayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">          <androidx.appcompat.widget.Toolbar             android:id="@+id/toolbar"             android:layout_width="match_parent"             android:layout_height="?attr/actionBarSize"             android:background="?attr/colorPrimary"             android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"             app:layout_scrollFlags="scroll|enterAlways"             app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />      </com.google.android.material.appbar.AppBarLayout>       <androidx.core.widget.NestedScrollView         android:layout_width="match_parent"         android:layout_height="match_parent"         app:layout_behavior="@string/appbar_scrolling_view_behavior">          <androidx.swiperefreshlayout.widget.SwipeRefreshLayout             android:id="@+id/swipe_refresh_layout"             android:layout_width="match_parent"             android:layout_height="match_parent">               <WebView                 android:id="@+id/wv"                 android:layout_width="match_parent"                 android:layout_height="match_parent" />           </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>     </androidx.core.widget.NestedScrollView>   </androidx.coordinatorlayout.widget.CoordinatorLayout>  
Add Comment
1 Answer(s)

You obviously need to use SwipeRefreshLayout outside of NestedScrollView:

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout     android:layout_width="match_parent"     android:layout_height="match_parent"     app:layout_behavior="@string/appbar_scrolling_view_behavior">      <androidx.core.widget.NestedScrollView         android:id="@+id/swipe_refresh_layout"         android:layout_width="match_parent"         android:layout_height="match_parent"> 

Also, please be aware of using WebView inside the NestedScrollView, they might not work properly without adding:

android:nestedScrollingEnabled="true" 

To the WebView. Also, set the android:layout_height of WebView to wrap_content, then it should work as expected.

Answered on July 17, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.