public
class
SwipeRefreshLayout
extends ViewGroup
implements
NestedScrollingParent,
NestedScrollingChild
java.lang.Object | |||
↳ | android.view.View | ||
↳ | android.view.ViewGroup | ||
↳ | android.support.v4.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.
Nested classes | |
---|---|
interface |
SwipeRefreshLayout.OnRefreshListener
Classes that wish to be notified when the swipe gesture correctly triggers a refresh should implement this interface. |
Inherited XML attributes | |
---|---|
From
class
android.view.ViewGroup
| |
From
class
android.view.View
|
Constants | |
---|---|
int |
DEFAULT
|
int |
LARGE
|
Inherited constants |
---|
From
class
android.view.ViewGroup
|
From
class
android.view.View
|
Fields | |
---|---|
protected
int |
mFrom
|
protected
int |
mOriginalOffsetTop
|
Inherited fields |
---|
From
class
android.view.View
|
Public constructors | |
---|---|
SwipeRefreshLayout(Context context)
Simple constructor to use when creating a SwipeRefreshLayout from code. |
|
SwipeRefreshLayout(Context context, AttributeSet attrs)
Constructor that is called when inflating SwipeRefreshLayout from XML. |
Public methods | |
---|---|
boolean
|
canChildScrollUp()
|
boolean
|
dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
Dispatch a fling to a nested scrolling parent. |
boolean
|
dispatchNestedPreFling(float velocityX, float velocityY)
Dispatch a fling to a nested scrolling parent before it is processed by this view. |
boolean
|
dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow)
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)
Dispatch one step of a nested scroll in progress. |
int
|
getNestedScrollAxes()
Return the current axes of nested scrolling for this ViewGroup. |
int
|
getProgressCircleDiameter()
Get the diameter of the progress circle that is displayed as part of the swipe to refresh layout. |
boolean
|
hasNestedScrollingParent()
Returns true if this view has a nested scrolling parent. |
boolean
|
isNestedScrollingEnabled()
Returns true if nested scrolling is enabled for this view. |
boolean
|
isRefreshing()
|
boolean
|
onInterceptTouchEvent(MotionEvent ev)
Implement this method to intercept all touch screen motion events. |
void
|
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
Measure the view and its content to determine the measured width and the measured height. |
boolean
|
onNestedFling(View target, float velocityX, float velocityY, boolean consumed)
Request a fling from a nested scroll. |
boolean
|
onNestedPreFling(View target, float velocityX, float velocityY)
React to a nested fling before the target view consumes it. |
void
|
onNestedPreScroll(View target, int dx, int dy, int[] consumed)
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)
React to a nested scroll in progress. |
void
|
onNestedScrollAccepted(View child, View target, int axes)
React to the successful claiming of a nested scroll operation. |
boolean
|
onStartNestedScroll(View child, View target, int nestedScrollAxes)
React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate. |
void
|
onStopNestedScroll(View target)
React to a nested scroll operation ending. |
boolean
|
onTouchEvent(MotionEvent ev)
Implement this method to handle touch screen motion events. |
void
|
requestDisallowInterceptTouchEvent(boolean b)
Called when a child does not want this parent and its ancestors to
intercept touch events with
|
void
|
setColorScheme(int... colors)
This method is deprecated.
Use |
void
|
setColorSchemeColors(int... colors)
Set the colors used in the progress animation. |
void
|
setColorSchemeResources(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
|
setNestedScrollingEnabled(boolean enabled)
Enable or disable nested scrolling for this view. |
void
|
setOnRefreshListener(SwipeRefreshLayout.OnRefreshListener listener)
Set the listener to be notified when a refresh is triggered via the swipe gesture. |
void
|
setProgressBackgroundColor(int colorRes)
This method is deprecated.
Use |
void
|
setProgressBackgroundColorSchemeColor(int color)
Set the background color of the progress spinner disc. |
void
|
setProgressBackgroundColorSchemeResource(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. |
boolean
|
startNestedScroll(int axes)
Begin a nestable scroll operation along the given axes. |
void
|
stopNestedScroll()
Stop a nested scroll in progress. |
Protected methods | |
---|---|
int
|
getChildDrawingOrder(int childCount, int i)
Returns the index of the child to draw for this iteration. |
void
|
onDetachedFromWindow()
This is called when the view is detached from a window. |
void
|
onLayout(boolean changed, int left, int top, int right, int bottom)
Called from layout when this view should assign a size and position to each of its children. |
Inherited methods | |
---|---|
From
class
android.view.ViewGroup
| |
From
class
android.view.View
| |
From
class
java.lang.Object
| |
From
interface
android.view.ViewParent
| |
From
interface
android.view.ViewManager
| |
From
interface
android.graphics.drawable.Drawable.Callback
| |
From
interface
android.view.KeyEvent.Callback
| |
From
interface
android.view.accessibility.AccessibilityEventSource
| |
From
interface
android.support.v4.view.NestedScrollingParent
| |
From
interface
android.support.v4.view.NestedScrollingChild
|
int DEFAULT
Constant Value: 1 (0x00000001)
int LARGE
Constant Value: 0 (0x00000000)
int mFrom
int mOriginalOffsetTop
SwipeRefreshLayout (Context context)
Simple constructor to use when creating a SwipeRefreshLayout from code.
SwipeRefreshLayout (Context context, AttributeSet attrs)
Constructor that is called when inflating SwipeRefreshLayout from XML.
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. |
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 detected
suitable conditions for a fling. Generally this means that a touch scroll has ended with a
velocity
in the direction of scrolling that meets or exceeds
the minimum fling velocity
along a scrollable axis.
If a nested scrolling child view would normally fling but it is at the edge of its own content, it can use this method to delegate the fling to its nested scrolling parent instead. The parent may optionally consume the fling or observe a child fling.
Parameters | |
---|---|
velocityX |
float :
Horizontal fling velocity in pixels per second |
velocityY |
float :
Vertical fling velocity in pixels per second |
consumed |
boolean :
true if the child consumed the fling, false otherwise |
Returns | |
---|---|
boolean |
true if the nested scrolling parent consumed or otherwise reacted to the fling |
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 touch
and what nested pre-scroll is to nested scroll. dispatchNestedPreFling
offsets an opportunity for the parent view in a nested fling to fully consume the fling
before the child view consumes it. If this method returns true
, a nested
parent 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 consume the 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:
dispatchNestedPreFling
; consume the fling and settle to a valid
position regardless.Views should also not offer fling velocities to nested parent views along an axis
where scrolling is not currently supported; a ScrollView
should not offer a horizontal fling velocity to its parents since scrolling along that
axis is not permitted and carrying velocity along that motion does not make sense.
Parameters | |
---|---|
velocityX |
float :
Horizontal fling velocity in pixels per second |
velocityY |
float :
Vertical fling velocity in pixels per second |
Returns | |
---|---|
boolean |
true if a nested scrolling parent consumed the fling |
boolean dispatchNestedPreScroll (int dx, int dy, int[] consumed, 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 nested
scrolling operation to consume some or all of the scroll operation before the child view
consumes it.
Parameters | |
---|---|
dx |
int :
Horizontal scroll distance in pixels |
dy |
int :
Vertical scroll distance in pixels |
consumed |
int :
Output. If not null, consumed[0] will contain the consumed component of dx
and consumed[1] the consumed dy. |
offsetInWindow |
int :
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. |
Returns | |
---|---|
boolean |
true if the parent consumed some or all of the scroll delta |
boolean dispatchNestedScroll (int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow)
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 | |
---|---|
dxConsumed |
int :
Horizontal distance in pixels consumed by this view during this scroll step |
dyConsumed |
int :
Vertical distance in pixels consumed by this view during this scroll step |
dxUnconsumed |
int :
Horizontal scroll distance in pixels not consumed by this view |
dyUnconsumed |
int :
Horizontal scroll distance in pixels not consumed by this view |
offsetInWindow |
int :
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. |
Returns | |
---|---|
boolean |
true if the event was dispatched, false if it could not be dispatched. |
int getNestedScrollAxes ()
Return the current axes of nested scrolling for this ViewGroup.
A ViewGroup returning something other than SCROLL_AXIS_NONE
is currently
acting as a nested scrolling parent for one or more descendant views in the hierarchy.
Returns | |
---|---|
int |
Flags indicating the current axes of nested scrolling |
int getProgressCircleDiameter ()
Get the diameter of the progress circle that is displayed as part of the swipe to refresh layout. This is not valid until a measure pass has completed.
Returns | |
---|---|
int |
Diameter in pixels of the progress circle view. |
boolean hasNestedScrollingParent ()
Returns true if this view has a nested scrolling parent.
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.
Returns | |
---|---|
boolean |
whether this view has a nested scrolling parent |
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 data about the scroll operation in progress to a compatible and cooperating nested scrolling parent.
Returns | |
---|---|
boolean |
true if nested scrolling is enabled |
boolean isRefreshing ()
Returns | |
---|---|
boolean |
Whether the SwipeRefreshWidget is actively showing refresh progress. |
boolean onInterceptTouchEvent (MotionEvent ev)
Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.
Using this function takes some care, as it has a fairly complicated
interaction with View.onTouchEvent(MotionEvent)
, and using it requires implementing
that method as well as this one in the correct way. Events will be
received in the following order:
ACTION_CANCEL
, and all further
events will be delivered to your onTouchEvent() method and no longer
appear here.
Parameters | |
---|---|
ev |
MotionEvent :
The motion event being dispatched down the hierarchy. |
Returns | |
---|---|
boolean |
Return true to steal motion events from the children and have them dispatched to this ViewGroup through onTouchEvent(). The current target will receive an ACTION_CANCEL event, and no further messages will be delivered here. |
void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
Measure the view and its content to determine the measured width and the
measured height. This method is invoked by measure(int, int)
and
should be overridden by subclasses to provide accurate and efficient
measurement of their contents.
CONTRACT: When overriding this method, you
must call setMeasuredDimension(int, int)
to store the
measured width and height of this view. Failure to do so will trigger an
IllegalStateException
, thrown by
measure(int, int)
. Calling the superclass'
onMeasure(int, int)
is a valid use.
The base class implementation of measure defaults to the background size,
unless a larger size is allowed by the MeasureSpec. Subclasses should
override onMeasure(int, int)
to provide better measurements of
their content.
If this method is overridden, it is the subclass's responsibility to make
sure the measured height and width are at least the view's minimum height
and width (getSuggestedMinimumHeight()
and
getSuggestedMinimumWidth()
).
Parameters | |
---|---|
widthMeasureSpec |
int :
horizontal space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec . |
heightMeasureSpec |
int :
vertical space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec . |
boolean onNestedFling (View target, float velocityX, float velocityY, boolean consumed)
Request a fling from a nested scroll.
This method signifies that a nested scrolling child has detected suitable conditions
for a fling. Generally this means that a touch scroll has ended with a
velocity
in the direction of scrolling that meets or exceeds
the minimum fling velocity
along a scrollable axis.
If a nested scrolling child view would normally fling but it is at the edge of its own content, it can use this method to delegate the fling to its nested scrolling parent instead. The parent may optionally consume the fling or observe a child fling.
Parameters | |
---|---|
target |
View :
View that initiated the nested scroll |
velocityX |
float :
Horizontal velocity in pixels per second |
velocityY |
float :
Vertical velocity in pixels per second |
consumed |
boolean :
true if the child consumed the fling, false otherwise |
Returns | |
---|---|
boolean |
true if this parent consumed or otherwise reacted to the fling |
boolean onNestedPreFling (View target, float velocityX, float velocityY)
React to a nested fling before the target view consumes it.
This method siginfies that a nested scrolling child has detected a fling with the given
velocity along each axis. Generally this means that a touch scroll has ended with a
velocity
in the direction of scrolling that meets or exceeds
the minimum fling velocity
along a scrollable axis.
If a nested scrolling parent is consuming motion as part of a
pre-scroll
, it may be appropriate for
it to also consume the pre-fling to complete that same motion. By returning
true
from this method, the parent indicates that the child should not
fling its own internal content as well.
Parameters | |
---|---|
target |
View :
View that initiated the nested scroll |
velocityX |
float :
Horizontal velocity in pixels per second |
velocityY |
float :
Vertical velocity in pixels per second |
Returns | |
---|---|
boolean |
true if this parent consumed the fling ahead of the target view |
void onNestedPreScroll (View target, int dx, int dy, int[] consumed)
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(int, int, int[], int[])
. 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 | |
---|---|
target |
View :
View that initiated the nested scroll |
dx |
int :
Horizontal scroll distance in pixels |
dy |
int :
Vertical scroll distance in pixels |
consumed |
int :
Output. The horizontal and vertical scroll distance consumed by this parent
|
void onNestedScroll (View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed)
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(View, View, int)
.
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 | |
---|---|
target |
View :
The descendent view controlling the nested scroll |
dxConsumed |
int :
Horizontal scroll distance in pixels already consumed by target |
dyConsumed |
int :
Vertical scroll distance in pixels already consumed by target |
dxUnconsumed |
int :
Horizontal scroll distance in pixels not consumed by target |
dyUnconsumed |
int :
Vertical scroll distance in pixels not consumed by target
|
void onNestedScrollAccepted (View child, View target, int axes)
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 | |
---|---|
child |
View :
Direct child of this ViewParent containing target |
target |
View :
View that initiated the nested scroll |
axes |
int :
Flags consisting of SCROLL_AXIS_HORIZONTAL ,
SCROLL_AXIS_VERTICAL or both |
boolean onStartNestedScroll (View child, View target, int nestedScrollAxes)
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(int)
. 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(View)
.
Parameters | |
---|---|
child |
View :
Direct child of this ViewParent containing target |
target |
View :
View that initiated the nested scroll |
nestedScrollAxes |
int :
Flags consisting of SCROLL_AXIS_HORIZONTAL ,
SCROLL_AXIS_VERTICAL or both |
Returns | |
---|---|
boolean |
true if this ViewParent accepts the nested scroll operation |
void onStopNestedScroll (View target)
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 | |
---|---|
target |
View :
View that initiated the nested scroll
|
boolean onTouchEvent (MotionEvent ev)
Implement this method to handle touch screen motion events.
If this method is used to detect click actions, it is recommended that
the actions be performed by implementing and calling
performClick()
. This will ensure consistent system behavior,
including:
ACTION_CLICK
when
accessibility features are enabled
Parameters | |
---|---|
ev |
MotionEvent :
The motion event. |
Returns | |
---|---|
boolean |
True if the event was handled, false otherwise. |
void requestDisallowInterceptTouchEvent (boolean b)
Called when a child does not want this parent and its ancestors to
intercept touch events with
onInterceptTouchEvent(MotionEvent)
.
This parent should pass this call onto its parents. This parent must obey this request for the duration of the touch (that is, only clear the flag after this parent has received an up or a cancel.
Parameters | |
---|---|
b |
boolean :
True if the child does not want the parent to
intercept touch events.
|
void setColorScheme (int... colors)
This method is deprecated.
Use setColorSchemeResources(int)
Parameters | |
---|---|
colors |
int
|
void setColorSchemeColors (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.
void setColorSchemeResources (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.
void setDistanceToTriggerSync (int distance)
Set the distance to trigger a sync in dips
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 nested
scrolling operations with a compatible parent view in the current hierarchy. If this
view does not implement nested scrolling this will have no effect. Disabling nested scrolling
while a nested scroll is in progress has the effect of stopping
the nested scroll.
Parameters | |
---|---|
enabled |
boolean :
true to enable nested scrolling, false to disable |
void setOnRefreshListener (SwipeRefreshLayout.OnRefreshListener listener)
Set the listener to be notified when a refresh is triggered via the swipe gesture.
Parameters | |
---|---|
listener |
SwipeRefreshLayout.OnRefreshListener
|
void setProgressBackgroundColor (int colorRes)
This method is deprecated.
Use setProgressBackgroundColorSchemeResource(int)
Parameters | |
---|---|
colorRes |
int
|
void setProgressBackgroundColorSchemeColor (int color)
Set the background color of the progress spinner disc.
void setProgressBackgroundColorSchemeResource (int colorRes)
Set the background color of the progress spinner disc.
Parameters | |
---|---|
colorRes |
int :
Resource id of the color.
|
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 | |
---|---|
scale |
boolean :
Set to true if there is no view at a higher z-order than
where the progress spinner is set to appear. |
end |
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.
|
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.
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. |
start |
int :
The offset in pixels from the top of this view at which the
progress spinner should appear. |
end |
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.
|
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 | |
---|---|
refreshing |
boolean :
Whether or not the view should show refresh progress.
|
void setSize (int size)
One of DEFAULT, or LARGE.
Parameters | |
---|---|
size |
int
|
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 case
of a touch scroll 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(boolean)
.
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(View, int, int, int, int)
.
Parameters | |
---|---|
axes |
int :
Flags consisting of a combination of SCROLL_AXIS_HORIZONTAL and/or
SCROLL_AXIS_VERTICAL . |
Returns | |
---|---|
boolean |
true if a cooperative parent was found and nested scrolling has been enabled for the current gesture. |
void stopNestedScroll ()
Stop a nested scroll in progress.
Calling this method when a nested scroll is not currently in progress is harmless.
int getChildDrawingOrder (int childCount, int i)
Returns the index of the child to draw for this iteration. Override this if you want to change the drawing order of children. By default, it returns i.
NOTE: In order for this method to be called, you must enable child ordering
first by calling setChildrenDrawingOrderEnabled(boolean)
.
Parameters | |
---|---|
childCount |
int
|
i |
int :
The current iteration. |
Returns | |
---|---|
int |
The index of the child to draw this iteration. |
void onDetachedFromWindow ()
This is called when the view is detached from a window. At this point it no longer has a surface for drawing.
void onLayout (boolean changed, int left, int top, int right, int bottom)
Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.
Parameters | |
---|---|
changed |
boolean :
This is a new size or position for this view |
left |
int :
Left position, relative to parent |
top |
int :
Top position, relative to parent |
right |
int :
Right position, relative to parent |
bottom |
int :
Bottom position, relative to parent
|