SwipeRefreshLayout
public class SwipeRefreshLayout extends ViewGroup implements NestedScrollingParent3, NestedScrollingParent2, NestedScrollingChild3, NestedScrollingChild2, NestedScrollingParent, NestedScrollingChild
| java.lang.Object | |||
| ↳ | 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 types |
|---|
public interface SwipeRefreshLayout.OnChildScrollUpCallbackClasses that wish to override |
public interface SwipeRefreshLayout.OnRefreshListenerClasses that wish to be notified when the swipe gesture correctly triggers a refresh should implement this interface. |
Protected fields |
|
|---|---|
int |
|
int |
Public constructors |
|---|
SwipeRefreshLayout(@NonNull Context context)Simple constructor to use when creating a SwipeRefreshLayout from code. |
SwipeRefreshLayout(@NonNull Context context, @Nullable AttributeSet attrs)Constructor that is called when inflating SwipeRefreshLayout from XML. |
Public methods |
|
|---|---|
boolean |
|
boolean |
dispatchKeyEvent(@Nullable KeyEvent event) |
boolean |
dispatchNestedFling(float velocityX, float velocityY, boolean consumed) |
boolean |
dispatchNestedPreFling(float velocityX, float velocityY) |
boolean |
dispatchNestedPreScroll( |
boolean |
dispatchNestedPreScroll(Dispatch one step of a nested scroll in progress before this view consumes any portion of it. |
boolean |
dispatchNestedScroll( |
boolean |
dispatchNestedScroll(Dispatch one step of a nested scroll in progress. |
void |
dispatchNestedScroll(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 |
hasNestedScrollingParent(int type)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( |
boolean |
onNestedPreFling(View target, float velocityX, float velocityY) |
void |
onNestedPreScroll(View target, int dx, int dy, int[] consumed) |
void |
onNestedPreScroll(React to a nested scroll in progress before the target view consumes a portion of the scroll. |
void |
onNestedScroll( |
void |
onNestedScroll(React to a nested scroll in progress. |
void |
onNestedScroll(React to a nested scroll in progress. |
void |
onNestedScrollAccepted(View child, View target, int axes) |
void |
onNestedScrollAccepted(React to the successful claiming of a nested scroll operation. |
boolean |
onStartNestedScroll(View child, View target, int axes) |
boolean |
onStartNestedScroll(React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate. |
void |
onStopNestedScroll(View target) |
void |
onStopNestedScroll(@NonNull View target, int type)React to a nested scroll operation ending. |
boolean |
|
void |
requestDisallowInterceptTouchEvent(boolean b) |
void |
This method is deprecated. |
void |
setColorSchemeColors(@ColorInt @NonNull int[] colors)Set the colors used in the progress animation. |
void |
setColorSchemeResources(@ColorRes @NonNull 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 |
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 |
void |
Set the listener to be notified when a refresh is triggered via the swipe gesture. |
void |
This method is deprecated. |
void |
setProgressBackgroundColorSchemeColor(@ColorInt int color)Set the background color of the progress spinner disc. |
void |
setProgressBackgroundColorSchemeResource(@ColorRes 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. |
void |
setSlingshotDistance(@Px int slingshotDistance)Sets the distance that the refresh indicator can be pulled beyond its resting position during a swipe gesture. |
boolean |
startNestedScroll(int axes) |
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 |
onRestoreInstanceState(Parcelable state) |
@NonNull Parcelable |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited methods |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
Protected fields
Public constructors
SwipeRefreshLayout
public SwipeRefreshLayout(@NonNull Context context)
Simple constructor to use when creating a SwipeRefreshLayout from code.
SwipeRefreshLayout
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
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)
dispatchNestedPreScroll
public boolean dispatchNestedPreScroll(
int dx,
int dy,
@Nullable int[] consumed,
@Nullable int[] offsetInWindow
)
dispatchNestedPreScroll
public boolean dispatchNestedPreScroll(
int dx,
int dy,
@Nullable int[] consumed,
@Nullable 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 |
@Nullable int[] consumed |
Output. If not null, consumed[0] will contain the consumed component of dx and consumed[1] the consumed dy. |
@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 |
| Returns | |
|---|---|
boolean |
true if the parent consumed some or all of the scroll delta |
| See also | |
|---|---|
dispatchNestedScroll |
dispatchNestedScroll
public boolean dispatchNestedScroll(
int dxConsumed,
int dyConsumed,
int dxUnconsumed,
int dyUnconsumed,
@Nullable int[] offsetInWindow
)
dispatchNestedScroll
public boolean dispatchNestedScroll(
int dxConsumed,
int dyConsumed,
int dxUnconsumed,
int dyUnconsumed,
@Nullable 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 |
@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 |
| Returns | |
|---|---|
boolean |
true if the event was dispatched, false if it could not be dispatched. |
| See also | |
|---|---|
dispatchNestedPreScroll |
dispatchNestedScroll
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 |
getProgressCircleDiameter
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
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
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(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 |
isRefreshing
public boolean isRefreshing()
| Returns | |
|---|---|
boolean |
Whether the SwipeRefreshWidget is actively showing refresh progress. |
onNestedFling
public boolean onNestedFling(
View target,
float velocityX,
float velocityY,
boolean consumed
)
onNestedPreScroll
public void onNestedPreScroll(
@NonNull View target,
int dx,
int dy,
@NonNull 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 | |
|---|---|
@NonNull View target |
View that initiated the nested scroll |
int dx |
Horizontal scroll distance in pixels |
int dy |
Vertical scroll distance in pixels |
@NonNull 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
public void onNestedScroll(
@NonNull 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 | |
|---|---|
@NonNull 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
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 |
| See also | |
|---|---|
dispatchNestedScroll |
onNestedScrollAccepted
public void onNestedScrollAccepted(
@NonNull View child,
@NonNull 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 | |
|---|---|
@NonNull View child |
Direct child of this ViewParent containing target |
@NonNull View target |
View that initiated the nested scroll |
int axes |
Flags consisting of |
int type |
the type of input which cause this scroll event |
| See also | |
|---|---|
onStartNestedScroll |
|
onStopNestedScroll |
onStartNestedScroll
public boolean onStartNestedScroll(
@NonNull View child,
@NonNull 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 | |
|---|---|
@NonNull View child |
Direct child of this ViewParent containing target |
@NonNull View target |
View that initiated the nested scroll |
int axes |
Flags consisting of |
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(@NonNull 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.
setColorSchemeColors
public void setColorSchemeColors(@ColorInt @NonNull 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
public void setColorSchemeResources(@ColorRes @NonNull 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
public void setDistanceToTriggerSync(int distance)
Set the distance to trigger a sync in dips
| Parameters | |
|---|---|
int distance |
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
AbsListViewand the runtime is API <21 - The child has nested scrolling disabled
- 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
truefixes that issue
| Parameters | |
|---|---|
boolean enabled |
|
setOnChildScrollUpCallback
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
public void setOnRefreshListener(
@Nullable SwipeRefreshLayout.OnRefreshListener listener
)
Set the listener to be notified when a refresh is triggered via the swipe gesture.
setProgressBackgroundColorSchemeColor
public void setProgressBackgroundColorSchemeColor(@ColorInt int color)
Set the background color of the progress spinner disc.
| Parameters | |
|---|---|
@ColorInt int color |
setProgressBackgroundColorSchemeResource
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
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
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
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. |
setSlingshotDistance
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, 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 |
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(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 |
| See also | |
|---|---|
startNestedScroll |