-
public interface NestedScrollingChild
This interface should be implemented by View subclasses that wish to support dispatching nested scrolling operations to a cooperating parent ViewGroup.
Classes implementing this interface should create a final instance of a NestedScrollingChildHelper as a field and delegate any View methods to the
NestedScrollingChildHelper
methods of the same signature.Views invoking nested scrolling functionality should always do so from the relevant ViewCompat, ViewGroupCompat or ViewParentCompat compatibility shim static methods. This ensures interoperability with nested scrolling views on Android 5.0 Lollipop and newer.
-
-
Method Summary
Modifier and Type Method Description abstract void
setNestedScrollingEnabled(boolean enabled)
Enable or disable nested scrolling for this view. abstract boolean
isNestedScrollingEnabled()
Returns true if nested scrolling is enabled for this view. abstract boolean
startNestedScroll(int axes)
Begin a nestable scroll operation along the given axes. abstract void
stopNestedScroll()
Stop a nested scroll in progress. abstract boolean
hasNestedScrollingParent()
Returns true if this view has a nested scrolling parent. abstract boolean
dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, @Nullable() Array<int> offsetInWindow)
Dispatch one step of a nested scroll in progress. abstract boolean
dispatchNestedPreScroll(int dx, int dy, @Nullable() Array<int> consumed, @Nullable() Array<int> offsetInWindow)
Dispatch one step of a nested scroll in progress before this view consumes any portion of it. abstract boolean
dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
Dispatch a fling to a nested scrolling parent. abstract boolean
dispatchNestedPreFling(float velocityX, float velocityY)
Dispatch a fling to a nested scrolling parent before it is processed by this view. -
-
Method Detail
-
setNestedScrollingEnabled
abstract void setNestedScrollingEnabled(boolean enabled)
Enable or disable nested scrolling for this view.
If this property is set to true the view will be permitted to initiate nestedscrolling operations with a compatible parent view in the current hierarchy. If thisview does not implement nested scrolling this will have no effect. Disabling nested scrollingwhile a nested scroll is in progress has the effect of stopping the nested scroll.
- Parameters:
enabled
- true to enable nested scrolling, false to disable
-
isNestedScrollingEnabled
abstract boolean isNestedScrollingEnabled()
Returns true if nested scrolling is enabled for this view.
If nested scrolling is enabled and this View class implementation supports it,this view will act as a nested scrolling child view when applicable, forwarding dataabout the scroll operation in progress to a compatible and cooperating nested scrollingparent.
-
startNestedScroll
abstract boolean startNestedScroll(int axes)
Begin a nestable scroll operation along the given axes.
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 caseof a touch scroll this corresponds to the initial ACTION_DOWN.In the case of touch scrolling the nested scroll will be terminated automatically inthe 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 scrollingparent at least partially consumed the scroll and the caller should adjust the amount itscrolls by.
After applying the remainder of the scroll delta the caller should invoke dispatchNestedScroll, passingboth the delta consumed and the delta unconsumed. A nested scrolling parent may treatthese values differently. See onNestedScroll.
- Parameters:
axes
- Flags consisting of a combination of SCROLL_AXIS_HORIZONTAL and/or SCROLL_AXIS_VERTICAL.
-
stopNestedScroll
abstract void stopNestedScroll()
Stop a nested scroll in progress.
Calling this method when a nested scroll is not currently in progress is harmless.
-
hasNestedScrollingParent
abstract boolean hasNestedScrollingParent()
Returns true if this view has a nested scrolling parent.
The presence of a nested scrolling parent indicates that this view has initiateda nested scroll and it was accepted by an ancestor view further up the view hierarchy.
-
dispatchNestedScroll
abstract boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, @Nullable() Array<int> offsetInWindow)
Dispatch one step of a nested scroll in progress.
Implementations of views that support nested scrolling should call this to reportinfo about a scroll in progress to the current nested scrolling parent. If a nested scrollis not currently in progress or nested scrolling is not enabled for this view this method does nothing.
Compatible View implementations should also call dispatchNestedPreScroll beforeconsuming a component of the scroll event themselves.
- Parameters:
dxConsumed
- Horizontal distance in pixels consumed by this view during this scroll stepdyConsumed
- Vertical distance in pixels consumed by this view during this scroll stepdxUnconsumed
- Horizontal scroll distance in pixels not consumed by this viewdyUnconsumed
- Horizontal scroll distance in pixels not consumed by this viewoffsetInWindow
- Optional.
-
dispatchNestedPreScroll
abstract boolean dispatchNestedPreScroll(int dx, int dy, @Nullable() Array<int> consumed, @Nullable() Array<int> offsetInWindow)
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 nestedscrolling operation to consume some or all of the scroll operation before the child viewconsumes it.- Parameters:
dx
- Horizontal scroll distance in pixelsdy
- Vertical scroll distance in pixelsconsumed
- Output.offsetInWindow
- Optional.
-
dispatchNestedFling
abstract boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
Dispatch a fling to a nested scrolling parent.
This method should be used to indicate that a nested scrolling child has detectedsuitable conditions for a fling. Generally this means that a touch scroll has ended with a velocity in the direction of scrolling that meets or exceedsthe minimum fling velocity along a scrollable axis.
If a nested scrolling child view would normally fling but it is at the edge ofits own content, it can use this method to delegate the fling to its nested scrollingparent instead. The parent may optionally consume the fling or observe a child fling.
- Parameters:
velocityX
- Horizontal fling velocity in pixels per secondvelocityY
- Vertical fling velocity in pixels per secondconsumed
- true if the child consumed the fling, false otherwise
-
dispatchNestedPreFling
abstract boolean dispatchNestedPreFling(float velocityX, float velocityY)
Dispatch a fling to a nested scrolling parent before it is processed by this view.
Nested pre-fling events are to nested fling events what touch intercept is to touchand what nested pre-scroll is to nested scroll.
dispatchNestedPreFling
offsets an opportunity for the parent view in a nested fling to fully consume the flingbefore the child view consumes it. If this method returnstrue
, a nestedparent view consumed the fling and this view should not scroll as a result.For a better user experience, only one view in a nested scrolling chain should consumethe fling at a time. If a parent view consumed the fling this method will return false.Custom view implementations should account for this in two ways:
- If a custom view is paged and needs to settle to a fixed page-point, do notcall
dispatchNestedPreFling
; consume the fling and settle to a validposition regardless. - If a nested parent does consume the fling, this view should not scroll at all,even to settle back to a valid idle position.
Views should also not offer fling velocities to nested parent views along an axiswhere scrolling is not currently supported; a ScrollView should not offer a horizontal fling velocity to its parents since scrolling along thataxis is not permitted and carrying velocity along that motion does not make sense.
- Parameters:
velocityX
- Horizontal fling velocity in pixels per secondvelocityY
- Vertical fling velocity in pixels per second
- If a custom view is paged and needs to settle to a fixed page-point, do notcall
-
-
-
-