Register now for Android Dev Summit 2019!

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(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

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 a custom slingshot distance.

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 Context:

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: Int, dyUnconsumed: Int, @Nullable offsetInWindow: IntArray?, type: Int, @NonNull consumed: IntArray): Unit

dispatchNestedScroll

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

dispatchNestedScroll

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

getNestedScrollAxes

open fun getNestedScrollAxes(): Int

getProgressCircleDiameter

open fun getProgressCircleDiameter(): Int

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

Return
Int: Diameter in pixels of the progress circle view.

getProgressViewEndOffset

open fun getProgressViewEndOffset(): Int
Return
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

open fun getProgressViewStartOffset(): Int
Return
Int: The offset in pixels from the top of this view at which the progress spinner should appear.

hasNestedScrollingParent

open fun hasNestedScrollingParent(type: Int): Boolean

hasNestedScrollingParent

open fun hasNestedScrollingParent(): Boolean

isNestedScrollingEnabled

open fun isNestedScrollingEnabled(): Boolean

isRefreshing

open fun isRefreshing(): Boolean
Return
Boolean: Whether the SwipeRefreshWidget is actively showing refresh progress.

onInterceptTouchEvent

open fun onInterceptTouchEvent(ev: MotionEvent!): Boolean

onMeasure

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

onNestedFling

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

onNestedPreFling

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

onNestedPreScroll

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

onNestedPreScroll

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

onNestedScroll

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

onNestedScroll

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

onNestedScroll

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

onNestedScrollAccepted

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

onNestedScrollAccepted

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

onStartNestedScroll

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

onStartNestedScroll

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

onStopNestedScroll

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

onStopNestedScroll

open fun onStopNestedScroll(target: View): Unit

onTouchEvent

open fun onTouchEvent(ev: MotionEvent!): Boolean

requestDisallowInterceptTouchEvent

open fun requestDisallowInterceptTouchEvent(b: Boolean): Unit

setColorScheme

open fun setColorScheme(@ColorRes vararg colors: Int): Unit

Deprecated: Use setColorSchemeResources(int...)

setColorSchemeColors

open fun setColorSchemeColors(vararg colors: Int): Unit

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
colors Int:

setColorSchemeResources

open fun setColorSchemeResources(@ColorRes vararg colorResIds: Int): Unit

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
colorResIds Int:

setDistanceToTriggerSync

open fun setDistanceToTriggerSync(distance: Int): Unit

Set the distance to trigger a sync in dips

Parameters
distance Int:

setEnabled

open fun setEnabled(enabled: Boolean): Unit

setNestedScrollingEnabled

open fun setNestedScrollingEnabled(enabled: Boolean): Unit

setOnChildScrollUpCallback

open fun setOnChildScrollUpCallback(@Nullable callback: SwipeRefreshLayout.OnChildScrollUpCallback?): Unit

Set a callback to override SwipeRefreshLayout#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

open fun setOnRefreshListener(@Nullable listener: SwipeRefreshLayout.OnRefreshListener?): Unit

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

setProgressBackgroundColor

open fun setProgressBackgroundColor(colorRes: Int): Unit

Deprecated: Use setProgressBackgroundColorSchemeResource(int)

setProgressBackgroundColorSchemeColor

open fun setProgressBackgroundColorSchemeColor(color: Int): Unit

Set the background color of the progress spinner disc.

Parameters
color Int:

setProgressBackgroundColorSchemeResource

open fun setProgressBackgroundColorSchemeResource(@ColorRes colorRes: Int): Unit

Set the background color of the progress spinner disc.

Parameters
colorRes Int: Resource id of the color.

setProgressViewEndTarget

open fun setProgressViewEndTarget(scale: Boolean, end: Int): Unit

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 Boolean: 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

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

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 Boolean: The offset in pixels from the top of this view at which the progress spinner should appear.
end Boolean: 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

open fun setRefreshing(refreshing: Boolean): Unit

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

open fun setSize(size: Int): Unit

One of DEFAULT, or LARGE.

setSlingshotDistance

open fun setSlingshotDistance(@Px slingshotDistance: Int): Unit

Sets a custom slingshot distance.

Parameters
slingshotDistance Int: The distance in pixels that the refresh indicator can be pulled beyond its resting position. Use DEFAULT_SLINGSHOT_DISTANCE to reset to the default value.

startNestedScroll

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

startNestedScroll

open fun startNestedScroll(axes: Int): Boolean

stopNestedScroll

open fun stopNestedScroll(type: Int): Unit

stopNestedScroll

open fun stopNestedScroll(): Unit

Protected methods

getChildDrawingOrder

protected open fun getChildDrawingOrder(childCount: Int, i: Int): Int

onDetachedFromWindow

protected open fun onDetachedFromWindow(): Unit

onLayout

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

onRestoreInstanceState

protected open fun onRestoreInstanceState(state: Parcelable!): Unit

onSaveInstanceState

protected open fun onSaveInstanceState(): Parcelable!

Properties

mFrom

protected var mFrom: Int

mOriginalOffsetTop

protected var mOriginalOffsetTop: Int