SwipeRefreshLayout


public class SwipeRefreshLayout extends ViewGroup implements NestedScrollingParent3, NestedScrollingParent2, NestedScrollingChild3, NestedScrollingChild2, NestedScrollingParent, NestedScrollingChild


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 types

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

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

Constants

static final int
static final int
static final int
LARGE = 0

Protected fields

int
int

Public constructors

Simple constructor to use when creating a SwipeRefreshLayout from code.

Constructor that is called when inflating SwipeRefreshLayout from XML.

Public methods

boolean
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
dispatchNestedPreScroll(
    int dx,
    int dy,
    int[] consumed,
    int[] offsetInWindow,
    int type
)

Dispatch one step of a nested scroll in progress before this view consumes any portion of it.

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

Dispatch one step of a nested scroll in progress.

void
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    @Nullable int[] offsetInWindow,
    int type,
    @NonNull int[] consumed
)

Dispatch one step of a nested scroll in progress.

int
int

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

int
int
boolean
boolean

Returns true if this view has a nested scrolling parent for the given input type.

boolean
boolean
boolean
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
onNestedPreScroll(View target, int dx, int dy, int[] consumed, int type)

React to a nested scroll in progress before the target view consumes a portion of the scroll.

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

React to a nested scroll in progress.

void
onNestedScroll(
    @NonNull View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int type,
    @NonNull int[] consumed
)

React to a nested scroll in progress.

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

React to the successful claiming of a nested scroll operation.

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

React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate.

void
void
onStopNestedScroll(View target, int type)

React to a nested scroll operation ending.

boolean
void
void
setColorScheme(@ColorRes int[] colors)

This method is deprecated.

Use setColorSchemeResources

void

Set the colors used in the progress animation.

void
setColorSchemeResources(@ColorRes int[] colorResIds)

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

void

Set the distance to trigger a sync in dips

void
setEnabled(boolean enabled)
void

This method is deprecated.

Only use this method if the changes introduced in requestDisallowInterceptTouchEvent in version 1.1.0-alpha03 and 1.1.1 are breaking your application.

void
setNestedScrollingEnabled(boolean enabled)
void

Set a callback to override canChildScrollUp method.

void

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

void

This method is deprecated.

Use setProgressBackgroundColorSchemeResource

void

Set the background color of the progress spinner disc.

void

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.

void
setSlingshotDistance(@Px int slingshotDistance)

Sets the distance that the refresh indicator can be pulled beyond its resting position during a swipe gesture.

boolean
boolean
startNestedScroll(int axes, int type)

Begin a nestable scroll operation along the given axes, for the given input type.

void
void
stopNestedScroll(int type)

Stop a nested scroll in progress for the given input type.

Protected methods

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

Inherited Constants

From android.view.View
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final int
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = "creditCardExpirationDate"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = "creditCardExpirationMonth"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = "creditCardExpirationYear"
static final String
static final String
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int
GONE = 8
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
KEEP_SCREEN_ON = 67108864
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
NO_ID = -1
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final String
VIEW_LOG_TAG = "View"
static final int
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
From android.view.ViewGroup
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

Inherited methods

From android.view.View
void
void
void
ViewPropertyAnimator
void
void
boolean
void
void

This method is deprecated.

void
boolean
boolean
boolean
boolean
boolean
canScrollHorizontally(int direction)
boolean
canScrollVertically(int direction)
final void
void
final void
boolean
void
void
static int
combineMeasuredStates(int curState, int newState)
int
int
int
void
WindowInsets
int
int
int
AccessibilityNodeInfo
void
void

This method is deprecated.

boolean
boolean
dispatchNestedPrePerformAccessibilityAction(
    int action,
    Bundle arguments
)
boolean
void
draw(Canvas canvas)
void
drawableHotspotChanged(float x, float y)
final OnBackInvokedDispatcher
final T
<T extends View> findViewById(int id)
final T
<T extends View> findViewWithTag(Object tag)
boolean

This method is deprecated.

void
forceHasOverlappingRendering(boolean hasOverlappingRendering)
void
void
generateDisplayHash(
    String hashAlgorithm,
    Rect bounds,
    Executor executor,
    DisplayHashResultCallback callback
)
static int
View.AccessibilityDelegate
int
AccessibilityNodeProvider
CharSequence
int
int
String
String
float
Animation
Matrix
IBinder
int[]
Map<IntegerInteger>
String[]
final AutofillId
int
AutofillValue
Drawable
BlendMode
ColorStateList
PorterDuff.Mode
int
final int
float
int
float
Rect
boolean
final boolean
final ContentCaptureSession
CharSequence
final Context
ContextMenu.ContextMenuInfo
final boolean
static int
getDefaultSize(int size, int measureSpec)
Display
final int[]
Bitmap

This method is deprecated.

int

This method is deprecated.

int

This method is deprecated.

void
long
float
int
boolean
boolean
int
ArrayList<View>
getFocusables(int direction)
void
Drawable
int
BlendMode
ColorStateList
PorterDuff.Mode
boolean
getGlobalVisibleRect(Rect r, Point globalOffset)
Handler
float
float
float
float
Runnable
final boolean
final int
void
getHitRect(Rect outRect)
int
int
Drawable
Drawable
int
int
int
int
boolean
KeyEvent.DispatcherState
int
int
int
ViewGroup.LayoutParams
final int
float
int
final boolean
void
getLocationInSurface(int[] location)
void
getLocationInWindow(int[] outLocation)
void
getLocationOnScreen(int[] outLocation)
Matrix
final int
final int
final int
final int
final int
int
int
int
int
int
int
int
int
View.OnFocusChangeListener
int
ViewOutlineProvider
int
int
ViewOverlay
int
int
int
int
int
int
final ViewParent
ViewParent
float
float
PointerIcon
final List<Rect>
String[]
Resources
final boolean
final int
float
int
AttachedSurfaceControl
View
WindowInsets
float
float
float
float
float
int
int
int
int
int
int
final int
final int
int
int
final CharSequence
StateListAnimator
int
int
List<Rect>
int

This method is deprecated.

Object
int
int
CharSequence
final int
float
int
TouchDelegate
ArrayList<View>
float
String
float
float
float
long
int
int
Drawable
Drawable
int
ViewTranslationResponse
ViewTreeObserver
int
final int
int
WindowId
WindowInsetsController
int

This method is deprecated.

IBinder
int
void
float
float
float
boolean
boolean
boolean
boolean
boolean
boolean
boolean
static View
inflate(Context context, int resource, ViewGroup root)
void

This method is deprecated.

void
void
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean

This method is deprecated.

boolean
boolean
final boolean
final boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
final boolean
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
View
keyboardNavigationClusterSearch(View currentCluster, int direction)
final void
measure(int widthMeasureSpec, int heightMeasureSpec)
static int[]
mergeDrawableStates(int[] baseState, int[] additionalState)
void
offsetLeftAndRight(int offset)
void
offsetTopAndBottom(int offset)
void
void
WindowInsets
void
boolean
boolean
void
void
InputConnection
void
onCreateViewTranslationRequest(
    int[] supportedFormats,
    Consumer<ViewTranslationRequest> requestsCollector
)
void
onCreateVirtualViewTranslationRequests(
    long[] virtualIds,
    int[] supportedFormats,
    Consumer<ViewTranslationRequest> requestsCollector
)
void
onDisplayHint(int hint)
boolean
void
onDraw(Canvas canvas)
void
final void
boolean
void
void
void
onFocusChanged(
    boolean gainFocus,
    int direction,
    Rect previouslyFocusedRect
)
boolean
void
onHoverChanged(boolean hovered)
boolean
void
void
boolean
onKeyDown(int keyCode, KeyEvent event)
boolean
onKeyLongPress(int keyCode, KeyEvent event)
boolean
onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
boolean
onKeyPreIme(int keyCode, KeyEvent event)
boolean
onKeyShortcut(int keyCode, KeyEvent event)
boolean
onKeyUp(int keyCode, KeyEvent event)
void
onOverScrolled(
    int scrollX,
    int scrollY,
    boolean clampedX,
    boolean clampedY
)
void
onPointerCaptureChange(boolean hasCapture)
void
void
onProvideAutofillStructure(ViewStructure structure, int flags)
void
void
void
void
ContentInfo
void
onRtlPropertiesChanged(int layoutDirection)
void
onScreenStateChanged(int screenState)
void
onScrollCaptureSearch(
    Rect localVisibleRect,
    Point windowOffset,
    Consumer<ScrollCaptureTarget> targets
)
void
onScrollChanged(int l, int t, int oldl, int oldt)
boolean
onSetAlpha(int alpha)
void
onSizeChanged(int w, int h, int oldw, int oldh)
void
boolean
void
void
void
onVisibilityAggregated(boolean isVisible)
void
onVisibilityChanged(View changedView, int visibility)
void
onWindowFocusChanged(boolean hasWindowFocus)
void

This method is deprecated.

void
onWindowVisibilityChanged(int visibility)
boolean
overScrollBy(
    int deltaX,
    int deltaY,
    int scrollX,
    int scrollY,
    int scrollRangeX,
    int scrollRangeY,
    int maxOverScrollX,
    int maxOverScrollY,
    boolean isTouchEvent
)
boolean
performAccessibilityAction(int action, Bundle arguments)
boolean
boolean
performContextClick(float x, float y)
boolean
performHapticFeedback(int feedbackConstant)
boolean
ContentInfo
void
playSoundEffect(int soundConstant)
boolean
post(Runnable action)
boolean
postDelayed(Runnable action, long delayMillis)
void
void
postInvalidateDelayed(long delayMilliseconds)
void
void
void
postOnAnimationDelayed(Runnable action, long delayMillis)
void
void
boolean
void
void
void
void
void

This method is deprecated.

final boolean
void
void
boolean
final void
final T
<T extends View> requireViewById(int id)
void
static int
resolveSize(int size, int measureSpec)
static int
resolveSizeAndState(int size, int measureSpec, int childMeasuredState)
void
final void
saveAttributeDataForStyleable(
    Context context,
    int[] styleable,
    AttributeSet attrs,
    TypedArray t,
    int defStyleAttr,
    int defStyleRes
)
void
void
scheduleDrawable(Drawable who, Runnable what, long when)
void
scrollBy(int x, int y)
void
scrollTo(int x, int y)
void
sendAccessibilityEvent(int eventType)
void
void
setAccessibilityDataSensitive(int accessibilityDataSensitive)
void
void
setAccessibilityHeading(boolean isHeading)
void
void
setAccessibilityPaneTitle(CharSequence accessibilityPaneTitle)
void
void
void
setActivated(boolean activated)
void
setAllowClickWhenDisabled(boolean clickableWhenDisabled)
void
void
void
setAlpha(float alpha)
void
void
void
setAutoHandwritingEnabled(boolean enabled)
void
setAutofillHints(String[] autofillHints)
void
void
setBackground(Drawable background)
void
setBackgroundColor(int color)
void

This method is deprecated.

void
void
void
void
final void
setBottom(int bottom)
void
setCameraDistance(float distance)
void
setClickable(boolean clickable)
void
setClipBounds(Rect clipBounds)
void
setClipToOutline(boolean clipToOutline)
void
void
setContentDescription(CharSequence contentDescription)
void
setContextClickable(boolean contextClickable)
void
setDefaultFocusHighlightEnabled(boolean defaultFocusHighlightEnabled)
void

This method is deprecated.

void
setDrawingCacheEnabled(boolean enabled)

This method is deprecated.

void

This method is deprecated.

void
void
setElevation(float elevation)
void
setFadingEdgeLength(int length)
void
void
setFitsSystemWindows(boolean fitSystemWindows)
void
setFocusable(boolean focusable)
void
setFocusableInTouchMode(boolean focusableInTouchMode)
void
setFocusedByDefault(boolean isFocusedByDefault)
void
setForceDarkAllowed(boolean allow)
void
setForeground(Drawable foreground)
void
setForegroundGravity(int gravity)
void
void
void
void
setHandwritingBoundsOffsets(
    float offsetLeft,
    float offsetTop,
    float offsetRight,
    float offsetBottom
)
void
void
setHapticFeedbackEnabled(boolean hapticFeedbackEnabled)
void
setHasTransientState(boolean hasTransientState)
void
setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled)
void
setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled)
void
void
void
setHovered(boolean hovered)
void
setId(int id)
void
void
void
void
setIsCredential(boolean isCredential)
void
setIsHandwritingDelegate(boolean isHandwritingDelegate)
void
setKeepScreenOn(boolean keepScreenOn)
void
setKeyboardNavigationCluster(boolean isCluster)
void
setLabelFor(int id)
void
void
setLayerType(int layerType, Paint paint)
void
setLayoutDirection(int layoutDirection)
void
final void
setLeft(int left)
final void
setLeftTopRightBottom(int left, int top, int right, int bottom)
void
setLongClickable(boolean longClickable)
final void
setMeasuredDimension(int measuredWidth, int measuredHeight)
void
setMinimumHeight(int minHeight)
void
setMinimumWidth(int minWidth)
void
setNextClusterForwardId(int nextClusterForwardId)
void
setNextFocusDownId(int nextFocusDownId)
void
setNextFocusForwardId(int nextFocusForwardId)
void
setNextFocusLeftId(int nextFocusLeftId)
void
setNextFocusRightId(int nextFocusRightId)
void
setNextFocusUpId(int nextFocusUpId)
void
void
void
void
void
void
void
void
void
void
void
void
setOnReceiveContentListener(
    String[] mimeTypes,
    OnReceiveContentListener listener
)
void
void

This method is deprecated.

void
void
void
void
void
setOverScrollMode(int overScrollMode)
void
setPadding(int left, int top, int right, int bottom)
void
setPaddingRelative(int start, int top, int end, int bottom)
void
setPivotX(float pivotX)
void
setPivotY(float pivotY)
void
final void
setPreferKeepClear(boolean preferKeepClear)
final void
void
setPressed(boolean pressed)
void
final void
setRevealOnFocusHint(boolean revealOnFocus)
final void
setRight(int right)
void
setRotation(float rotation)
void
setRotationX(float rotationX)
void
setRotationY(float rotationY)
void
setSaveEnabled(boolean enabled)
void
setSaveFromParentEnabled(boolean enabled)
void
setScaleX(float scaleX)
void
setScaleY(float scaleY)
void
setScreenReaderFocusable(boolean screenReaderFocusable)
void
setScrollBarDefaultDelayBeforeFade(
    int scrollBarDefaultDelayBeforeFade
)
void
setScrollBarFadeDuration(int scrollBarFadeDuration)
void
setScrollBarSize(int scrollBarSize)
void
setScrollBarStyle(int style)
final void
void
void
setScrollContainer(boolean isScrollContainer)
void
setScrollIndicators(int indicators)
void
setScrollX(int value)
void
setScrollY(int value)
void
setScrollbarFadingEnabled(boolean fadeScrollbars)
void
setSelected(boolean selected)
void
setSoundEffectsEnabled(boolean soundEffectsEnabled)
void
void
void
void
setSystemUiVisibility(int visibility)

This method is deprecated.

void
void
setTextAlignment(int textAlignment)
void
setTextDirection(int textDirection)
void
final void
setTop(int top)
void
void
setTransitionAlpha(float alpha)
final void
setTransitionName(String transitionName)
void
setTransitionVisibility(int visibility)
void
setTranslationX(float translationX)
void
setTranslationY(float translationY)
void
setTranslationZ(float translationZ)
void
setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled)
void
setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled)
void
void
void
void
void
setVisibility(int visibility)
void
setWillNotCacheDrawing(boolean willNotCacheDrawing)

This method is deprecated.

void
setWillNotDraw(boolean willNotDraw)
void
setX(float x)
void
setY(float y)
void
setZ(float z)
boolean
ActionMode
void
final boolean
startDrag(
    ClipData data,
    View.DragShadowBuilder shadowBuilder,
    Object myLocalState,
    int flags
)

This method is deprecated.

final boolean
startDragAndDrop(
    ClipData data,
    View.DragShadowBuilder shadowBuilder,
    Object myLocalState,
    int flags
)
String
void
void
void
final void
boolean
boolean

This method is deprecated.

boolean
From android.view.ViewGroup
void
void
addExtraDataToAccessibilityNodeInfo(
    AccessibilityNodeInfo info,
    String extraDataKey,
    Bundle arguments
)
void
addFocusables(ArrayList<View> views, int direction, int focusableMode)
void
boolean
void
void
addView(View child)
boolean
addViewInLayout(View child, int index, ViewGroup.LayoutParams params)
void
attachLayoutAnimationParameters(
    View child,
    ViewGroup.LayoutParams params,
    int index,
    int count
)
void
attachViewToParent(View child, int index, ViewGroup.LayoutParams params)
void
boolean
boolean
void
void
childHasTransientStateChanged(
    View child,
    boolean childHasTransientState
)
void
void
void
void
void
debug(int depth)
void
void
void
detachViewsFromParent(int start, int count)
WindowInsets
boolean
void
void
dispatchCreateViewTranslationRequest(
    Map<AutofillId, long[]> viewIds,
    int[] supportedFormats,
    TranslationCapability capability,
    List<ViewTranslationRequest> requests
)
void
boolean
void
void
dispatchDrawableHotspotChanged(float x, float y)
void
void
boolean
boolean
boolean
boolean
boolean
boolean
void
dispatchPointerCaptureChanged(boolean hasCapture)
void
void
void
void
void
dispatchScrollCaptureSearch(
    Rect localVisibleRect,
    Point windowOffset,
    Consumer<ScrollCaptureTarget> targets
)
void
dispatchSetActivated(boolean activated)
void
dispatchSetPressed(boolean pressed)
void
dispatchSetSelected(boolean selected)
void
void

This method is deprecated.

void
boolean
boolean
boolean
dispatchUnhandledMove(View focused, int direction)
void
dispatchVisibilityChanged(View changedView, int visibility)
void
dispatchWindowFocusChanged(boolean hasFocus)
void
void
WindowInsets
WindowInsetsAnimation.Bounds
void

This method is deprecated.

void
boolean
drawChild(Canvas canvas, View child, long drawingTime)
void
void
View
OnBackInvokedDispatcher
void
findViewsWithText(
    ArrayList<View> outViews,
    CharSequence text,
    int flags
)
View
focusSearch(View focused, int direction)
void
boolean
ViewGroup.LayoutParams
ViewGroup.LayoutParams
CharSequence
View
getChildAt(int index)
int
static int
getChildMeasureSpec(int spec, int padding, int childDimension)
boolean
boolean
getChildVisibleRect(View child, Rect r, Point offset)
boolean
boolean
int
View
LayoutAnimationController
Animation.AnimationListener
int
LayoutTransition
ViewGroupOverlay
int

This method is deprecated.

boolean
boolean
boolean
int
final void
invalidateChild(View child, Rect dirty)

This method is deprecated.

ViewParent
invalidateChildInParent(int[] location, Rect dirty)

This method is deprecated.

boolean

This method is deprecated.

boolean

This method is deprecated.

boolean
boolean

This method is deprecated.

boolean
boolean
boolean
void
final void
layout(int l, int t, int r, int b)
void
measureChild(
    View child,
    int parentWidthMeasureSpec,
    int parentHeightMeasureSpec
)
void
measureChildWithMargins(
    View child,
    int parentWidthMeasureSpec,
    int widthUsed,
    int parentHeightMeasureSpec,
    int heightUsed
)
void
measureChildren(int widthMeasureSpec, int heightMeasureSpec)
void
notifySubtreeAccessibilityStateChanged(
    View child,
    View source,
    int changeType
)
final void
final void
void
int[]
onCreateDrawableState(int extraSpace)
void
boolean
boolean
onNestedPrePerformAccessibilityAction(
    View target,
    int action,
    Bundle args
)
boolean
onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)
boolean
PointerIcon
onResolvePointerIcon(MotionEvent event, int pointerIndex)
void
void
void
void
void
void
removeDetachedView(View child, boolean animate)
void
void
removeViewAt(int index)
void
void
removeViews(int start, int count)
void
removeViewsInLayout(int start, int count)
void
requestChildFocus(View child, View focused)
boolean
requestChildRectangleOnScreen(
    View child,
    Rect rectangle,
    boolean immediate
)
boolean
requestFocus(int direction, Rect previouslyFocusedRect)
boolean
void
boolean
void
void
setAddStatesFromChildren(boolean addsStates)
void

This method is deprecated.

void
setAnimationCacheEnabled(boolean enabled)

This method is deprecated.

void

This method is deprecated.

void
void

This method is deprecated.

void
setClipChildren(boolean clipChildren)
void
setClipToPadding(boolean clipToPadding)
void
setDescendantFocusability(int focusability)
void
void
void
setLayoutMode(int layoutMode)
void
void
void
void
setPersistentDrawingCache(int drawingCacheToKeep)

This method is deprecated.

void
void
setTouchscreenBlocksFocus(boolean touchscreenBlocksFocus)
void
setTransitionGroup(boolean isTransitionGroup)
void
boolean
boolean
ActionMode
startActionModeForChild(
    View originalView,
    ActionMode.Callback callback
)
void
void
void
suppressLayout(boolean suppress)
void

Constants

DEFAULT

Added in 1.0.0
public static final int DEFAULT = 1

DEFAULT_SLINGSHOT_DISTANCE

Added in 1.0.0
public static final int DEFAULT_SLINGSHOT_DISTANCE = -1

LARGE

Added in 1.0.0
public static final int LARGE = 0

Protected fields

mFrom

Added in 1.0.0
protected int mFrom

mOriginalOffsetTop

Added in 1.0.0
protected int mOriginalOffsetTop

Public constructors

SwipeRefreshLayout

Added in 1.0.0
public SwipeRefreshLayout(@NonNull Context context)

Simple constructor to use when creating a SwipeRefreshLayout from code.

Parameters
@NonNull Context context

SwipeRefreshLayout

Added in 1.0.0
public SwipeRefreshLayout(@NonNull Context context, @Nullable AttributeSet attrs)

Constructor that is called when inflating SwipeRefreshLayout from XML.

Parameters
@NonNull Context context
@Nullable AttributeSet attrs

Public methods

canChildScrollUp

Added in 1.0.0
public 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

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

dispatchNestedPreFling

public boolean dispatchNestedPreFling(float velocityX, float velocityY)

dispatchNestedPreScroll

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

dispatchNestedPreScroll

Added in 1.1.0
public boolean dispatchNestedPreScroll(
    int dx,
    int dy,
    int[] consumed,
    int[] offsetInWindow,
    int type
)

Dispatch one step of a nested scroll in progress before this view consumes any portion of it.

Nested pre-scroll events are to nested scroll events what touch intercept is to touch. dispatchNestedPreScroll offers an opportunity for the parent view in a nested scrolling operation to consume some or all of the scroll operation before the child view consumes it.

Parameters
int dx

Horizontal scroll distance in pixels

int dy

Vertical scroll distance in pixels

int[] consumed

Output. If not null, consumed[0] will contain the consumed component of dx and consumed[1] the consumed dy.

int[] offsetInWindow

Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking.

int type

the type of input which cause this scroll event

Returns
boolean

true if the parent consumed some or all of the scroll delta

dispatchNestedScroll

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

dispatchNestedScroll

Added in 1.1.0
public boolean dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int[] offsetInWindow,
    int type
)

Dispatch one step of a nested scroll in progress.

Implementations of views that support nested scrolling should call this to report info about a scroll in progress to the current nested scrolling parent. If a nested scroll is not currently in progress or nested scrolling is not enabled for this view this method does nothing.

Compatible View implementations should also call dispatchNestedPreScroll before consuming a component of the scroll event themselves.

Parameters
int dxConsumed

Horizontal distance in pixels consumed by this view during this scroll step

int dyConsumed

Vertical distance in pixels consumed by this view during this scroll step

int dxUnconsumed

Horizontal scroll distance in pixels not consumed by this view

int dyUnconsumed

Horizontal scroll distance in pixels not consumed by this view

int[] offsetInWindow

Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking.

int type

the type of input which cause this scroll event

Returns
boolean

true if the event was dispatched, false if it could not be dispatched.

dispatchNestedScroll

Added in 1.1.0
public void dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    @Nullable int[] offsetInWindow,
    int type,
    @NonNull int[] consumed
)

Dispatch one step of a nested scroll in progress.

Implementations of views that support nested scrolling should call this to report info about a scroll in progress to the current nested scrolling parent. If a nested scroll is not currently in progress or nested scrolling is not enabled for this view this method does nothing.

Compatible View implementations should also call dispatchNestedPreScroll before consuming a component of the scroll event themselves.

The original nested scrolling child (where the input events were received to start the scroll) must provide a non-null consumed parameter with values {0, 0}.

Parameters
int dxConsumed

Horizontal distance in pixels consumed by this view during this scroll step

int dyConsumed

Vertical distance in pixels consumed by this view during this scroll step

int dxUnconsumed

Horizontal scroll distance in pixels not consumed by this view

int dyUnconsumed

Horizontal scroll distance in pixels not consumed by this view

@Nullable int[] offsetInWindow

Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking.

int type

the type of input which cause this scroll event

@NonNull int[] consumed

Output. Upon this method returning, will contain the original values plus any scroll distances consumed by all of this view's nested scrolling parents up the view hierarchy. Index 0 for the x dimension, and index 1 for the y dimension

See also
onNestedScroll

getNestedScrollAxes

public int getNestedScrollAxes()

getProgressCircleDiameter

Added in 1.0.0
public 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 1.0.0
public 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 1.0.0
public int getProgressViewStartOffset()
Returns
int

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

hasNestedScrollingParent

public boolean hasNestedScrollingParent()

hasNestedScrollingParent

Added in 1.1.0
public boolean hasNestedScrollingParent(int type)

Returns true if this view has a nested scrolling parent for the given input type.

The presence of a nested scrolling parent indicates that this view has initiated a nested scroll and it was accepted by an ancestor view further up the view hierarchy.

Parameters
int type

the type of input which cause this scroll event

Returns
boolean

whether this view has a nested scrolling parent

isNestedScrollingEnabled

public boolean isNestedScrollingEnabled()

isRefreshing

Added in 1.0.0
public boolean isRefreshing()
Returns
boolean

Whether the SwipeRefreshWidget is actively showing refresh progress.

onInterceptTouchEvent

public boolean onInterceptTouchEvent(MotionEvent ev)

onMeasure

Added in 1.0.0
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

onNestedFling

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

onNestedPreFling

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

onNestedPreScroll

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

onNestedPreScroll

Added in 1.1.0
public void onNestedPreScroll(View target, int dx, int dy, int[] consumed, int type)

React to a nested scroll in progress before the target view consumes a portion of the scroll.

When working with nested scrolling often the parent view may want an opportunity to consume the scroll before the nested scrolling child does. An example of this is a drawer that contains a scrollable list. The user will want to be able to scroll the list fully into view before the list itself begins scrolling.

onNestedPreScroll is called when a nested scrolling child invokes dispatchNestedPreScroll. The implementation should report how any pixels of the scroll reported by dx, dy were consumed in the consumed array. Index 0 corresponds to dx and index 1 corresponds to dy. This parameter will never be null. Initial values for consumed[0] and consumed[1] will always be 0.

Parameters
View target

View that initiated the nested scroll

int dx

Horizontal scroll distance in pixels

int dy

Vertical scroll distance in pixels

int[] consumed

Output. The horizontal and vertical scroll distance consumed by this parent

int type

the type of input which cause this scroll event

onNestedScroll

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

onNestedScroll

Added in 1.1.0
public void onNestedScroll(
    View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int type
)

React to a nested scroll in progress.

This method will be called when the ViewParent's current nested scrolling child view dispatches a nested scroll event. To receive calls to this method the ViewParent must have previously returned true for a call to onStartNestedScroll.

Both the consumed and unconsumed portions of the scroll distance are reported to the ViewParent. An implementation may choose to use the consumed portion to match or chase scroll position of multiple child elements, for example. The unconsumed portion may be used to allow continuous dragging of multiple scrolling or draggable elements, such as scrolling a list within a vertical drawer where the drawer begins dragging once the edge of inner scrolling content is reached.

Parameters
View target

The descendent view controlling the nested scroll

int dxConsumed

Horizontal scroll distance in pixels already consumed by target

int dyConsumed

Vertical scroll distance in pixels already consumed by target

int dxUnconsumed

Horizontal scroll distance in pixels not consumed by target

int dyUnconsumed

Vertical scroll distance in pixels not consumed by target

int type

the type of input which cause this scroll event

onNestedScroll

Added in 1.1.0
public void onNestedScroll(
    @NonNull View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int type,
    @NonNull int[] consumed
)

React to a nested scroll in progress.

This method will be called when the ViewParent's current nested scrolling child view dispatches a nested scroll event. To receive calls to this method the ViewParent must have previously returned true for a call to onStartNestedScroll.

Both the consumed and unconsumed portions of the scroll distance are reported to the ViewParent. An implementation may choose to use the consumed portion to match or chase scroll position of multiple child elements, for example. The unconsumed portion may be used to allow continuous dragging of multiple scrolling or draggable elements, such as scrolling a list within a vertical drawer where the drawer begins dragging once the edge of inner scrolling content is reached.

This method is called when a nested scrolling child invokes dispatchNestedScroll} or one of methods it overloads.

An implementation must report how many pixels of the the x and y scroll distances were consumed by this nested scrolling parent by adding the consumed distances to the consumed parameter. If this View also implements NestedScrollingChild3, consumed should also be passed up to it's nested scrolling parent so that the parent may also add any scroll distance it consumes. Index 0 corresponds to dx and index 1 corresponds to dy.

Parameters
@NonNull View target

The descendant view controlling the nested scroll

int dxConsumed

Horizontal scroll distance in pixels already consumed by target

int dyConsumed

Vertical scroll distance in pixels already consumed by target

int dxUnconsumed

Horizontal scroll distance in pixels not consumed by target

int dyUnconsumed

Vertical scroll distance in pixels not consumed by target

int type

the type of input which cause this scroll event

@NonNull int[] consumed

Output. Upon this method returning, will contain the scroll distances consumed by this nested scrolling parent and the scroll distances consumed by any other parent up the view hierarchy

onNestedScrollAccepted

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

onNestedScrollAccepted

Added in 1.1.0
public void onNestedScrollAccepted(View child, View target, int axes, int type)

React to the successful claiming of a nested scroll operation.

This method will be called after onStartNestedScroll returns true. It offers an opportunity for the view and its superclasses to perform initial configuration for the nested scroll. Implementations of this method should always call their superclass's implementation of this method if one is present.

Parameters
View child

Direct child of this ViewParent containing target

View target

View that initiated the nested scroll

int axes

Flags consisting of SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_VERTICAL or both

int type

the type of input which cause this scroll event

onStartNestedScroll

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

onStartNestedScroll

Added in 1.1.0
public boolean onStartNestedScroll(View child, View target, int axes, int type)

React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate.

This method will be called in response to a descendant view invoking startNestedScroll. Each parent up the view hierarchy will be given an opportunity to respond and claim the nested scrolling operation by returning true.

This method may be overridden by ViewParent implementations to indicate when the view is willing to support a nested scrolling operation that is about to begin. If it returns true, this ViewParent will become the target view's nested scrolling parent for the duration of the scroll operation in progress. When the nested scroll is finished this ViewParent will receive a call to onStopNestedScroll.

Parameters
View child

Direct child of this ViewParent containing target

View target

View that initiated the nested scroll

int axes

Flags consisting of SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_VERTICAL or both

int type

the type of input which cause this scroll event

Returns
boolean

true if this ViewParent accepts the nested scroll operation

onStopNestedScroll

public void onStopNestedScroll(View target)

onStopNestedScroll

Added in 1.1.0
public void onStopNestedScroll(View target, int type)

React to a nested scroll operation ending.

Perform cleanup after a nested scrolling operation. This method will be called when a nested scroll stops, for example when a nested touch scroll ends with a ACTION_UP or ACTION_CANCEL event. Implementations of this method should always call their superclass's implementation of this method if one is present.

Parameters
View target

View that initiated the nested scroll

int type

the type of input which cause this scroll event

onTouchEvent

public boolean onTouchEvent(MotionEvent ev)

requestDisallowInterceptTouchEvent

public void requestDisallowInterceptTouchEvent(boolean b)

setColorScheme

public void setColorScheme(@ColorRes int[] colors)

setColorSchemeColors

public void setColorSchemeColors(@ColorInt 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.

Parameters
@ColorInt int[] colors

setColorSchemeResources

public void setColorSchemeResources(@ColorRes 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.

Parameters
@ColorRes int[] colorResIds

setDistanceToTriggerSync

Added in 1.0.0
public void setDistanceToTriggerSync(int distance)

Set the distance to trigger a sync in dips

Parameters
int distance

setEnabled

public void setEnabled(boolean enabled)

setLegacyRequestDisallowInterceptTouchEventEnabled

Added in 1.1.0
Deprecated in 1.1.0
public void setLegacyRequestDisallowInterceptTouchEventEnabled(boolean enabled)

Enables the legacy behavior of requestDisallowInterceptTouchEvent from before 1.1.0-alpha03, where the request is neither honored, nor propagated up to its parents, in either of the following two cases:

  • The child as an AbsListView and the runtime is API <21
  • The child has nested scrolling disabled
Use this method only if your application:
  • is upgrading SwipeRefreshLayout from <1.1.1 to >= 1.1.0-alpha03
  • has a SwipeRefreshLayout, or its parent, that no longer responds to touch events when it should
  • setting this method to true fixes that issue
Parameters
boolean enabled

true to enable the legacy behavior, false for default behavior

setNestedScrollingEnabled

public void setNestedScrollingEnabled(boolean enabled)

setOnChildScrollUpCallback

Added in 1.0.0
public void setOnChildScrollUpCallback(
    @Nullable 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
@Nullable SwipeRefreshLayout.OnChildScrollUpCallback callback

Callback that should be called when canChildScrollUp() is called.

setOnRefreshListener

Added in 1.0.0
public void setOnRefreshListener(
    @Nullable SwipeRefreshLayout.OnRefreshListener listener
)

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

setProgressBackgroundColor

Added in 1.0.0
Deprecated in 1.0.0
public void setProgressBackgroundColor(int colorRes)

setProgressBackgroundColorSchemeColor

Added in 1.0.0
public void setProgressBackgroundColorSchemeColor(@ColorInt int color)

Set the background color of the progress spinner disc.

Parameters
@ColorInt int color

setProgressBackgroundColorSchemeResource

Added in 1.0.0
public void setProgressBackgroundColorSchemeResource(@ColorRes int colorRes)

Set the background color of the progress spinner disc.

Parameters
@ColorRes int colorRes

Resource id of the color.

setProgressViewEndTarget

Added in 1.0.0
public 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
boolean scale

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.

int end

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 1.0.0
public 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
boolean scale

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.

int start

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

int end

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 1.0.0
public 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
boolean refreshing

Whether or not the view should show refresh progress.

setSize

Added in 1.0.0
public void setSize(int size)

One of DEFAULT, or LARGE.

setSlingshotDistance

Added in 1.0.0
public void setSlingshotDistance(@Px int slingshotDistance)

Sets the distance that the refresh indicator can be pulled beyond its resting position during a swipe gesture. The default is DEFAULT_SLINGSHOT_DISTANCE.

Parameters
@Px int slingshotDistance

The distance in pixels that the refresh indicator can be pulled beyond its resting position.

startNestedScroll

public boolean startNestedScroll(int axes)

startNestedScroll

Added in 1.1.0
public boolean startNestedScroll(int axes, int type)

Begin a nestable scroll operation along the given axes, for the given input type.

A view starting a nested scroll promises to abide by the following contract:

The view will call startNestedScroll upon initiating a scroll operation. In the case of a touch scroll type this corresponds to the initial ACTION_DOWN. In the case of touch scrolling the nested scroll will be terminated automatically in the same manner as requestDisallowInterceptTouchEvent. In the event of programmatic scrolling the caller must explicitly call stopNestedScroll to indicate the end of the nested scroll.

If startNestedScroll returns true, a cooperative parent was found. If it returns false the caller may ignore the rest of this contract until the next scroll. Calling startNestedScroll while a nested scroll is already in progress will return true.

At each incremental step of the scroll the caller should invoke dispatchNestedPreScroll once it has calculated the requested scrolling delta. If it returns true the nested scrolling parent at least partially consumed the scroll and the caller should adjust the amount it scrolls by.

After applying the remainder of the scroll delta the caller should invoke dispatchNestedScroll, passing both the delta consumed and the delta unconsumed. A nested scrolling parent may treat these values differently. See onNestedScroll.

Parameters
int axes

Flags consisting of a combination of SCROLL_AXIS_HORIZONTAL and/or SCROLL_AXIS_VERTICAL.

int type

the type of input which cause this scroll event

Returns
boolean

true if a cooperative parent was found and nested scrolling has been enabled for the current gesture.

stopNestedScroll

public void stopNestedScroll()

stopNestedScroll

Added in 1.1.0
public void stopNestedScroll(int type)

Stop a nested scroll in progress for the given input type.

Calling this method when a nested scroll is not currently in progress is harmless.

Parameters
int type

the type of input which cause this scroll event

Protected methods

getChildDrawingOrder

protected int getChildDrawingOrder(int childCount, int i)

onDetachedFromWindow

protected void onDetachedFromWindow()

onLayout

protected void onLayout(boolean changed, int left, int top, int right, int bottom)

onRestoreInstanceState

protected void onRestoreInstanceState(Parcelable state)

onSaveInstanceState

protected Parcelable onSaveInstanceState()