added in version 22.1.0
belongs to Maven artifact com.android.support:swiperefreshlayout:28.0.0-alpha1

SwipeRefreshLayout

public class SwipeRefreshLayout
extends ViewGroup implements NestedScrollingParent, NestedScrollingChild

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.support.v4.widget.SwipeRefreshLayout


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.

Summary

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. 

Constants

int DEFAULT

int LARGE

Inherited constants

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

Fields

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)

One of DEFAULT, or LARGE.

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
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource
From interface android.support.v4.view.NestedScrollingParent
From interface android.support.v4.view.NestedScrollingChild

Constants

DEFAULT

added in version 22.1.0
int DEFAULT

Constant Value: 1 (0x00000001)

LARGE

added in version 22.1.0
int LARGE

Constant Value: 0 (0x00000000)

Fields

mFrom

added in version 22.1.0
int mFrom

mOriginalOffsetTop

added in version 22.1.0
int mOriginalOffsetTop

Public constructors

SwipeRefreshLayout

added in version 22.1.0
SwipeRefreshLayout (Context context)

Simple constructor to use when creating a SwipeRefreshLayout from code.

SwipeRefreshLayout

added in version 22.1.0
SwipeRefreshLayout (Context context, 
                AttributeSet attrs)

Constructor that is called when inflating SwipeRefreshLayout from XML.

Public methods

canChildScrollUp

added in version 22.1.0
boolean canChildScrollUp ()

Returns
boolean Whether it is possible for the child view of this layout to scroll up. Override this if the child view is a custom view.

dispatchNestedFling

boolean dispatchNestedFling (float velocityX, 
                float velocityY, 
                boolean consumed)

Parameters
velocityX float

velocityY float

consumed boolean

Returns
boolean

dispatchNestedPreFling

boolean dispatchNestedPreFling (float velocityX, 
                float velocityY)

Parameters
velocityX float

velocityY float

Returns
boolean

dispatchNestedPreScroll

boolean dispatchNestedPreScroll (int dx, 
                int dy, 
                int[] consumed, 
                int[] offsetInWindow)

Parameters
dx int

dy int

consumed int

offsetInWindow int

Returns
boolean

dispatchNestedScroll

boolean dispatchNestedScroll (int dxConsumed, 
                int dyConsumed, 
                int dxUnconsumed, 
                int dyUnconsumed, 
                int[] offsetInWindow)

Parameters
dxConsumed int

dyConsumed int

dxUnconsumed int

dyUnconsumed int

offsetInWindow int

Returns
boolean

getNestedScrollAxes

int getNestedScrollAxes ()

Returns
int

getProgressCircleDiameter

added in version 22.1.0
int getProgressCircleDiameter ()

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

Returns
int Diameter in pixels of the progress circle view.

getProgressViewEndOffset

added in version 25.1.0
int getProgressViewEndOffset ()

Returns
int The offset in pixels from the top of this view at which the progress spinner should come to rest after a successful swipe gesture.

getProgressViewStartOffset

added in version 25.1.0
int getProgressViewStartOffset ()

Returns
int The offset in pixels from the top of this view at which the progress spinner should appear.

hasNestedScrollingParent

boolean hasNestedScrollingParent ()

Returns
boolean

isNestedScrollingEnabled

boolean isNestedScrollingEnabled ()

Returns
boolean

isRefreshing

added in version 22.1.0
boolean isRefreshing ()

Returns
boolean Whether the SwipeRefreshWidget is actively showing refresh progress.

onInterceptTouchEvent

boolean onInterceptTouchEvent (MotionEvent ev)

Parameters
ev MotionEvent

Returns
boolean

onMeasure

added in version 22.1.0
void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int

onNestedFling

boolean onNestedFling (View target, 
                float velocityX, 
                float velocityY, 
                boolean consumed)

Parameters
target View

velocityX float

velocityY float

consumed boolean

Returns
boolean

onNestedPreFling

boolean onNestedPreFling (View target, 
                float velocityX, 
                float velocityY)

Parameters
target View

velocityX float

velocityY float

Returns
boolean

onNestedPreScroll

void onNestedPreScroll (View target, 
                int dx, 
                int dy, 
                int[] consumed)

Parameters
target View

dx int

dy int

consumed int

onNestedScroll

void onNestedScroll (View target, 
                int dxConsumed, 
                int dyConsumed, 
                int dxUnconsumed, 
                int dyUnconsumed)

Parameters
target View

dxConsumed int

dyConsumed int

dxUnconsumed int

dyUnconsumed int

onNestedScrollAccepted

void onNestedScrollAccepted (View child, 
                View target, 
                int axes)

Parameters
child View

target View

axes int

onStartNestedScroll

boolean onStartNestedScroll (View child, 
                View target, 
                int nestedScrollAxes)

Parameters
child View

target View

nestedScrollAxes int

Returns
boolean

onStopNestedScroll

void onStopNestedScroll (View target)

Parameters
target View

onTouchEvent

boolean onTouchEvent (MotionEvent ev)

Parameters
ev MotionEvent

Returns
boolean

requestDisallowInterceptTouchEvent

void requestDisallowInterceptTouchEvent (boolean b)

Parameters
b boolean

setColorScheme

added in version 22.1.0
void setColorScheme (int... colors)

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

Parameters
colors int

setColorSchemeColors

added in version 22.1.0
void setColorSchemeColors (int... colors)

Set the colors used in the progress animation. The first color will also be the color of the bar that grows in response to a user swipe gesture.

setColorSchemeResources

added in version 22.1.0
void setColorSchemeResources (int... colorResIds)

Set the color resources used in the progress animation from color resources. The first color will also be the color of the bar that grows in response to a user swipe gesture.

setDistanceToTriggerSync

added in version 22.1.0
void setDistanceToTriggerSync (int distance)

Set the distance to trigger a sync in dips

setEnabled

void setEnabled (boolean enabled)

Parameters
enabled boolean

setNestedScrollingEnabled

void setNestedScrollingEnabled (boolean enabled)

Parameters
enabled boolean

setOnChildScrollUpCallback

added in version 25.1.0
void setOnChildScrollUpCallback (SwipeRefreshLayout.OnChildScrollUpCallback callback)

Set a callback to override canChildScrollUp() method. Non-null callback will return the value provided by the callback and ignore all internal logic.

Parameters
callback SwipeRefreshLayout.OnChildScrollUpCallback: Callback that should be called when canChildScrollUp() is called.

setOnRefreshListener

added in version 22.1.0
void setOnRefreshListener (SwipeRefreshLayout.OnRefreshListener listener)

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

Parameters
listener SwipeRefreshLayout.OnRefreshListener

setProgressBackgroundColor

added in version 22.1.0
void setProgressBackgroundColor (int colorRes)

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

Parameters
colorRes int

setProgressBackgroundColorSchemeColor

added in version 22.1.0
void setProgressBackgroundColorSchemeColor (int color)

Set the background color of the progress spinner disc.

setProgressBackgroundColorSchemeResource

added in version 22.1.0
void setProgressBackgroundColorSchemeResource (int colorRes)

Set the background color of the progress spinner disc.

Parameters
colorRes int: Resource id of the color.

setProgressViewEndTarget

added in version 22.1.0
void setProgressViewEndTarget (boolean scale, 
                int end)

The refresh indicator resting position is always positioned near the top of the refreshing content. This position is a consistent location, but can be adjusted in either direction based on whether or not there is a toolbar or actionbar present.

Parameters
scale boolean: Set to true if there is no view at a higher z-order than where the progress spinner is set to appear. Setting it to true will cause indicator to be scaled up rather than clipped.

end int: The offset in pixels from the top of this view at which the progress spinner should come to rest after a successful swipe gesture.

setProgressViewOffset

added in version 22.1.0
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. This position is a consistent location, but can be adjusted in either direction based on whether or not there is a toolbar or actionbar present.

Note: Calling this will reset the position of the refresh indicator to start.

Parameters
scale boolean: Set to true if there is no view at a higher z-order than where the progress spinner is set to appear. Setting it to true will cause indicator to be scaled up rather than clipped.

start int: The offset in pixels from the top of this view at which the progress spinner should appear.

end int: The offset in pixels from the top of this view at which the progress spinner should come to rest after a successful swipe gesture.

setRefreshing

added in version 22.1.0
void setRefreshing (boolean refreshing)

Notify the widget that refresh state has changed. Do not call this when refresh is triggered by a swipe gesture.

Parameters
refreshing boolean: Whether or not the view should show refresh progress.

setSize

added in version 22.1.0
void setSize (int size)

One of DEFAULT, or LARGE.

Parameters
size int

startNestedScroll

boolean startNestedScroll (int axes)

Parameters
axes int

Returns
boolean

stopNestedScroll

void stopNestedScroll ()

Protected methods

getChildDrawingOrder

int getChildDrawingOrder (int childCount, 
                int i)

Parameters
childCount int

i int

Returns
int

onDetachedFromWindow

void onDetachedFromWindow ()

onLayout

added in version 22.1.0
void onLayout (boolean changed, 
                int left, 
                int top, 
                int right, 
                int bottom)

Parameters
changed boolean

left int

top int

right int

bottom int