Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add pull to refresh in Coordinator layout

I have an AppBar and RecyclerView in CoordiantorLayout. SwipeToRefresh has to be fullscreen but RecyclerView not scrolling down then.

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="128dp"/>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />


    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


</androidx.coordinatorlayout.widget.CoordinatorLayout>

oid

How to add fullscreen pull to refresh in Coordinator layout without a library.

like image 416
6155031 Avatar asked Nov 06 '19 08:11

6155031


People also ask

What is pull to refresh layout in Android?

Before getting into example, we should know what is Pull to refresh layout in android . we can call pull to refresh in android as swipe-to-refresh. when you swipe screen from top to bottom it will do some action based on setOnRefreshListener. This example demonstrate about how to implement android pull to refresh.

How do I use coordinator layout effectively?

The best example of how to use coordinator layout effectively is to refer carefully to the source code for cheesesquare. This repository is a sample repo kept updated by Google to reflect best practices with coordinating behaviors. In particular, see the layout for a tabbed ViewPager list and this for a layout for a detail view.

How to implement pull-to-refresh layout in Android?

How to implement Android Pull-to-Refresh? Before getting into example, we should know what is Pull to refresh layout in android . we can call pull to refresh in android as swipe-to-refresh. when you swipe screen from top to bottom it will do some action based on setOnRefreshListener.

How to create a recyclerview inside a coordinatorlayout?

The secondary way is to create them is using an additional RecyclerView nested inside a CoordinatorLayout. This RecyclerView will be hidden by default if the layout_behavior defined is set using the pre-defined @string/bottom_sheet_behavior value.


1 Answers

You can disable swipe refresh layout when AppBar isn't fully expanded and enable it if it is fully expanded.

vAppBar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
   vSwipeRefresh.isEnabled = verticalOffset == 0
}) 
like image 131
arsent Avatar answered Sep 30 '22 19:09

arsent