Recycler View Not Scrolling Properly After Implementing Swipe To Refresh Layout
Solution 1:
I troubleshooted it myself finally.
The problem lies in the xml layout itself. Recycler view should be a single child element inside a SwipeToReferesh layout.
The layout file should be as follows:
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"xmlns:wheel="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"><android.support.v4.widget.SwipeRefreshLayoutandroid:id="@+id/activity_main_swipe_refresh_layout"android:layout_width="match_parent"android:layout_height="match_parent"><android.support.v7.widget.RecyclerViewandroid:id="@+id/completedTaskRecyclerView"android:layout_width="match_parent"android:layout_height="wrap_content"android:scrollbars="vertical" /></android.support.v4.widget.SwipeRefreshLayout><com.pnikosis.materialishprogress.ProgressWheelandroid:id="@+id/progress_wheel"android:layout_width="50dp"android:layout_height="50dp"android:layout_centerHorizontal="true"android:layout_centerVertical="true"android:visibility="gone"tools:visibility="visible"wheel:matProg_barColor="@color/colorAccent"wheel:matProg_barWidth="1dp"wheel:matProg_progressIndeterminate="true" /><TextViewandroid:id="@+id/no_available_tasks"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_centerVertical="true"android:gravity="center_horizontal|center_vertical"android:padding="16dp"android:text="No tasks currently available. Pull to refresh"android:textSize="18sp"android:visibility="gone"tools:visibility="visible" /></RelativeLayout>
No need to add some other utility classes or override SwipeToRefesh's canChildScrollUp() method.
Solution 2:
This is a known issue and I wonder why this has been not fixed already. The problem here is that SwipeRefreshLayout
always assumes that the list cannot scroll upwards any further.
One solution is to extend SwipeRefreshLayout
and override canChildScrollUp()
. This method gets called when you start scrolling and returning false here when the list is not at its top position should do the trick.
Next, use this utility method to determine whether or not your RecyclerView
can scroll further upwards:
/**
* Returns whether or not a View can scroll vertically any further.
* @param downwardScroll The direction to check for. Pass true for downwards and
* false for upward. Note that downward scroll == upward swipe
* */publicstaticbooleancanScrollVerticallyAnyFurther(View view, boolean downwardScroll){
return view.canScrollVertically(downwardScroll ? +1 : -1);
}
Solution 3:
I managed to implement Swipe down to refresh and infinite scrolling. If anyone is interested check out.You can see implementation of this at
https://github.com/snijsure/TwitterSample
Although from UX perspective I am not sure if supporting SwipeDown to refresh as well as refresh on end of scroll, is a good idea, it might be to confusing to the end user.
Cheers!
Post a Comment for "Recycler View Not Scrolling Properly After Implementing Swipe To Refresh Layout"