SwipeRefreshLayout With NestedScrollView — Android

Refresh you View Content with SwipeRefreshLayout

Danish Amjad
AndroidPub
Published in
2 min readAug 26, 2019

--

Introduction:

In Android we have SwipeRefreshLayout, we often used this in our layouts to refresh the content of a view with the vertical gesture feature, whenever we need it. The SwipeRefreshLayout can only support direct one child only, so whenever we need to add in our layout, we always try to add before our RecyclerView like this below code snippet:

Visit my website at https://danishamjad.com/

Recently I have been working in an Application where I have a RecyclerView with CoolapingToolbar and NestedScrollView, and I need to add a SwipeRefreshLayout, so I just Implemented the way it looked above simply put the SwipRefreshLayout above the RecyclerView.

After that, I just run the application and guess what, nothing happened and the data was not showing in the list, so then I figured it out what’s goes wrong in the Implementation.

How to Solve:

The solution is very simple, We need to add a SwipRefreshLayout above the NestedScrollView and So you should move app:layout_behavior="@string/appbar_scrolling_view_behavior" from NestedScrollView to SwipeRefreshLayout.

That’s it just runs your application and sees the results.

Let’s see with the XML File.

SwipRefreshLayout With NestedScrollView

Conclusion:

This article described you how to Implement the SwipeRefreshLayoyut with NestedScrollView, hows the Implementation is different from the traditional one.

I hope this article is helpful. If you think something is missing, have questions, or would like to give feedback, go ahead and leave a comment below. I’d appreciate the feedback.

I’ve written some other Android-related content, and if you liked what you read here, you’ll probably also enjoy this:

Enjoy and Happy Coding!

Sharing (knowledge) is caring 😊 Thanks for reading this article. Be sure to clap or recommend this article if you found it helpful. It means a lot to me.

If you need any help then Join me on Twitter, LinkedIn, GitHub, and Subscribe to my Youtube Channel.

--

--

Danish Amjad
AndroidPub

Senior Mobile Engineer (Android). Open Source Contributor, Technical Writer, ✉️ Dani.amjad12@gmail.com 🔗 https://danishamjad12.github.io