Stay organized with collections Save and categorize content based on your preferences.
added in version 22.1.0
belongs to Maven artifact


public class SwipeRefreshLayout
extends ViewGroup implements NestedScrollingParent, NestedScrollingChild

   ↳ android.view.View
     ↳ android.view.ViewGroup

The SwipeRefreshLayout should be used whenever the user can refresh the contents of a view via a vertical swipe gesture. The activity that instantiates this view should add an OnRefreshListener to be notified whenever the swipe to refresh gesture is completed. The SwipeRefreshLayout will notify the listener each and every time the gesture is completed again; the listener is responsible for correctly determining when to actually initiate a refresh of its content. If the listener determines there should not be a refresh, it must call setRefreshing(false) to cancel any visual indication of a refresh. If an activity wishes to show just the progress animation, it should call setRefreshing(true). To disable the gesture and progress animation, call setEnabled(false) on the view.

This layout should be made the parent of the view that will be refreshed as a result of the gesture and can only support one direct child. This view will also be made the target of the gesture and will be forced to match both the width and the height supplied in this layout. The SwipeRefreshLayout does not provide accessibility events; instead, a menu item must be provided to allow refresh of the content wherever this gesture is used.


Nested classes

interface SwipeRefreshLayout.OnChildScrollUpCallback

Classes that wish to override canChildScrollUp() method behavior should implement this interface. 

interface SwipeRefreshLayout.OnRefreshListener

Classes that wish to be notified when the swipe gesture correctly triggers a refresh should implement this interface. 




Inherited constants

From class android.view.ViewGroup
From class android.view.View


protected int mFrom

protected int mOriginalOffsetTop

Inherited fields

From class android.view.View

Public constructors

SwipeRefreshLayout(Context context)

Simple constructor to use when creating a SwipeRefreshLayout from code.

SwipeRefreshLayout(Context context, AttributeSet attrs)

Constructor that is called when inflating SwipeRefreshLayout from XML.

Public methods

boolean canChildScrollUp()
boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
boolean dispatchNestedPreFling(float velocityX, float velocityY)
boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow)
boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow)
int getNestedScrollAxes()
int getProgressCircleDiameter()

Get the diameter of the progress circle that is displayed as part of the swipe to refresh layout.

int getProgressViewEndOffset()
int getProgressViewStartOffset()
boolean hasNestedScrollingParent()
boolean isNestedScrollingEnabled()
boolean isRefreshing()
boolean onInterceptTouchEvent(MotionEvent ev)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed)
boolean onNestedPreFling(View target, float velocityX, float velocityY)
void onNestedPreScroll(View target, int dx, int dy, int[] consumed)
void onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed)
void onNestedScrollAccepted(View child, View target, int axes)
boolean onStartNestedScroll(View child, View target, int nestedScrollAxes)
void onStopNestedScroll(View target)
boolean onTouchEvent(MotionEvent ev)
void requestDisallowInterceptTouchEvent(boolean b)
void setColorScheme(int... colors)

This method was deprecated in API level 22.1.0. Use setColorSchemeResources(int)

void setColorSchemeColors(int... colors)

Set the colors used in the progress animation.

void setColorSchemeResources(int... colorResIds)

Set the color resources used in the progress animation from color resources.

void setDistanceToTriggerSync(int distance)

Set the distance to trigger a sync in dips

void setEnabled(boolean enabled)
void setNestedScrollingEnabled(boolean enabled)
void setOnChildScrollUpCallback(SwipeRefreshLayout.OnChildScrollUpCallback callback)

Set a callback to override canChildScrollUp() method.

void setOnRefreshListener(SwipeRefreshLayout.OnRefreshListener listener)

Set the listener to be notified when a refresh is triggered via the swipe gesture.

void setProgressBackgroundColor(int colorRes)

This method was deprecated in API level 22.1.0. Use setProgressBackgroundColorSchemeResource(int)

void setProgressBackgroundColorSchemeColor(int color)

Set the background color of the progress spinner disc.

void setProgressBackgroundColorSchemeResource(int colorRes)

Set the background color of the progress spinner disc.

void setProgressViewEndTarget(boolean scale, int end)

The refresh indicator resting position is always positioned near the top of the refreshing content.

void setProgressViewOffset(boolean scale, int start, int end)

The refresh indicator starting and resting position is always positioned near the top of the refreshing content.

void setRefreshing(boolean refreshing)

Notify the widget that refresh state has changed.

void setSize(int size)


boolean startNestedScroll(int axes)
void stopNestedScroll()

Protected methods

int getChildDrawingOrder(int childCount, int i)
void onDetachedFromWindow()
void onLayout(boolean changed, int left, int top, int right, int bottom)

Inherited methods

From class android.view.ViewGroup
From class android.view.View