Google is committed to advancing racial equity for Black communities. See how.

SwipeRefreshLayout

open class SwipeRefreshLayout : ViewGroup, NestedScrollingParent3, NestedScrollingParent2, NestedScrollingChild3, NestedScrollingChild2, NestedScrollingParent, NestedScrollingChild
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ androidx.swiperefreshlayout.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
abstract

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

abstract

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

Constants
static Int

static Int

static Int

Public constructors
<init>(@NonNull context: Context)

Simple constructor to use when creating a SwipeRefreshLayout from code.

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?)

Constructor that is called when inflating SwipeRefreshLayout from XML.

Public methods
open Boolean

open Boolean
dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean)

open Boolean
dispatchNestedPreFling(velocityX: Float, velocityY: Float)

open Boolean
dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?, type: Int)

open Boolean
dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?)

open Unit
dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, @Nullable offsetInWindow: IntArray?, type: Int, @NonNull consumed: IntArray)

open Boolean
dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, offsetInWindow: IntArray?, type: Int)

open Boolean
dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, offsetInWindow: IntArray?)

open Int

open Int

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

open Int

open Int

open Boolean

open Boolean

open Boolean

open Boolean

open Boolean

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

open Boolean
onNestedFling(target: View, velocityX: Float, velocityY: Float, consumed: Boolean)

open Boolean
onNestedPreFling(target: View, velocityX: Float, velocityY: Float)

open Unit
onNestedPreScroll(target: View, dx: Int, dy: Int, consumed: IntArray, type: Int)

open Unit
onNestedPreScroll(target: View, dx: Int, dy: Int, consumed: IntArray)

open Unit
onNestedScroll(@NonNull target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, type: Int, @NonNull consumed: IntArray)

open Unit
onNestedScroll(target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, type: Int)

open Unit
onNestedScroll(target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int)

open Unit
onNestedScrollAccepted(child: View, target: View, axes: Int, type: Int)

open Unit
onNestedScrollAccepted(child: View, target: View, axes: Int)

open Boolean
onStartNestedScroll(child: View, target: View, axes: Int, type: Int)

open Boolean
onStartNestedScroll(child: View, target: View, nestedScrollAxes: Int)

open Unit
onStopNestedScroll(target: View, type: Int)

open Unit

open Boolean

open Unit

open Unit
setColorScheme(@ColorRes vararg colors: Int)

open Unit
setColorSchemeColors(@ColorInt vararg colors: Int)

Set the colors used in the progress animation.

open Unit
setColorSchemeResources(@ColorRes vararg colorResIds: Int)

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

open Unit

Set the distance to trigger a sync in dips

open Unit
setEnabled(enabled: Boolean)

open Unit

Enables the legacy behavior of #requestDisallowInterceptTouchEvent from before 1.

open Unit

open Unit

Set a callback to override SwipeRefreshLayout#canChildScrollUp() method.

open Unit

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

open Unit

open Unit

Set the background color of the progress spinner disc.

open Unit

Set the background color of the progress spinner disc.

open Unit

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

open Unit
setProgressViewOffset(scale: Boolean, start: Int, end: Int)

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

open Unit
setRefreshing(refreshing: Boolean)

Notify the widget that refresh state has changed.

open Unit
setSize(size: Int)

One of DEFAULT, or LARGE.

open Unit
setSlingshotDistance(@Px slingshotDistance: Int)

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

open Boolean
startNestedScroll(axes: Int, type: Int)

open Boolean

open Unit

open Unit

Protected methods
open Int
getChildDrawingOrder(childCount: Int, i: Int)

open Unit

open Unit
onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int)

open Unit

open Parcelable?

Properties
Int

Int

Constants

DEFAULT

static val DEFAULT: Int
Value: CircularProgressDrawable.DEFAULT

DEFAULT_SLINGSHOT_DISTANCE

static val DEFAULT_SLINGSHOT_DISTANCE: Int
Value: -1

LARGE

static val LARGE: Int
Value: CircularProgressDrawable.LARGE

Public constructors

<init>

SwipeRefreshLayout(@NonNull context: Context)

Simple constructor to use when creating a SwipeRefreshLayout from code.

Parameters
context Context:

<init>

SwipeRefreshLayout(
    @NonNull context: Context,
    @Nullable attrs: AttributeSet?)

Constructor that is called when inflating SwipeRefreshLayout from XML.

Parameters
context Context:
attrs AttributeSet?:

Public methods

canChildScrollUp

open fun canChildScrollUp(): Boolean
Return
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

open fun dispatchNestedFling(
    velocityX: Float,
    velocityY: Float,
    consumed: Boolean
): Boolean

dispatchNestedPreFling

open fun dispatchNestedPreFling(
    velocityX: Float,
    velocityY: Float
): Boolean

dispatchNestedPreScroll

open fun dispatchNestedPreScroll(
    dx: Int,
    dy: Int,
    consumed: IntArray?,
    offsetInWindow: IntArray?,
    type: Int
): Boolean

dispatchNestedPreScroll

open fun dispatchNestedPreScroll(
    dx: Int,
    dy: Int,
    consumed: IntArray?,
    offsetInWindow: IntArray?
): Boolean

dispatchNestedScroll

open fun dispatchNestedScroll(
    dxConsumed: Int,
    dyConsumed: Int,
    dxUnconsumed: