java.lang.Object | |
↳ | android.support.design.widget.CoordinatorLayout.Behavior<V extends android.view.View> |
Known Direct Subclasses |
Interaction behavior plugin for child views of CoordinatorLayout
.
A Behavior implements one or more interactions that a user can take on a child view. These interactions may include drags, swipes, flings, or any other gestures.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Default constructor for instantiating Behaviors.
| |||||||||||
Default constructor for inflating Behaviors from layout.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Determine whether interaction with views behind the given child in the child order
should be blocked.
| |||||||||||
Supply a scrim color that will be painted behind the associated child view.
| |||||||||||
Determine the current opacity of the scrim behind a given child view
A scrim may be used to indicate that the other elements beneath it are not currently interactive or actionable, drawing user focus and attention to the views above the scrim. | |||||||||||
Get the behavior-specific tag object with the given child view.
| |||||||||||
Determine whether the given child view should be considered dirty.
| |||||||||||
Determine whether the supplied child view has another specific sibling view as a
layout dependency.
| |||||||||||
Called when the window insets have changed.
| |||||||||||
Respond to a change in a child's dependent view
This method is called whenever a dependent view changes in size or position outside of the standard layout flow. | |||||||||||
Respond to a child's dependent view being removed.
| |||||||||||
Respond to CoordinatorLayout touch events before they are dispatched to child views.
| |||||||||||
Called when the parent CoordinatorLayout is about the lay out the given child view.
| |||||||||||
Called when the parent CoordinatorLayout is about to measure the given child view.
| |||||||||||
Called when a nested scrolling child is starting a fling or an action that would
be a fling.
| |||||||||||
Called when a nested scrolling child is about to start a fling.
| |||||||||||
Called when a nested scroll in progress is about to update, before the target has
consumed any of the scrolled distance.
| |||||||||||
Called when a nested scroll in progress has updated and the target has scrolled or
attempted to scroll.
| |||||||||||
Called when a nested scroll has been accepted by the CoordinatorLayout.
| |||||||||||
Hook allowing a behavior to re-apply a representation of its internal state that had
previously been generated by
onSaveInstanceState(CoordinatorLayout, V) .
| |||||||||||
Hook allowing a behavior to generate a representation of its internal state
that can later be used to create a new instance with that same state.
| |||||||||||
Called when a descendant of the CoordinatorLayout attempts to initiate a nested scroll.
| |||||||||||
Called when a nested scroll has ended.
| |||||||||||
Respond to CoordinatorLayout touch events after this Behavior has started
intercepting them.
| |||||||||||
Associate a Behavior-specific tag object with the given child view.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Default constructor for instantiating Behaviors.
Default constructor for inflating Behaviors from layout. The Behavior will have the opportunity to parse specially defined layout parameters. These parameters will appear on the child view tag.
Determine whether interaction with views behind the given child in the child order should be blocked.
The default implementation returns true if
getScrimOpacity(CoordinatorLayout, android.view.View)
would return > 0.0f.
parent | the parent view of the given child |
---|---|
child | the child view to test |
getScrimOpacity(CoordinatorLayout, android.view.View)
would
return > 0.0f.
Supply a scrim color that will be painted behind the associated child view.
A scrim may be used to indicate that the other elements beneath it are not currently interactive or actionable, drawing user focus and attention to the views above the scrim.
The default implementation returns BLACK
.
parent | the parent view of the given child |
---|---|
child | the child view above the scrim |
BLACK
.Determine the current opacity of the scrim behind a given child view
A scrim may be used to indicate that the other elements beneath it are not currently interactive or actionable, drawing user focus and attention to the views above the scrim.
The default implementation returns 0.0f.
parent | the parent view of the given child |
---|---|
child | the child view above the scrim |
Get the behavior-specific tag object with the given child view. This object is stored with the child view's LayoutParams.
child | child view to get tag with |
---|
Determine whether the given child view should be considered dirty.
If a property determined by the Behavior such as other dependent views would change, the Behavior should report a child view as dirty. This will prompt the CoordinatorLayout to re-query Behavior-determined properties as appropriate.
parent | the parent view of the given child |
---|---|
child | the child view to check |
Determine whether the supplied child view has another specific sibling view as a layout dependency.
This method will be called at least once in response to a layout request. If it returns true for a given child and dependency view pair, the parent CoordinatorLayout will:
onDependentViewChanged(CoordinatorLayout, V, View)
when the dependency view's layout or
position changes.parent | the parent view of the given child |
---|---|
child | the child view to test |
dependency | the proposed dependency of child |
Called when the window insets have changed.
Any Behavior associated with the direct child of the CoordinatorLayout may elect to handle the window inset change on behalf of it's associated view.
coordinatorLayout | the CoordinatorLayout parent of the view this Behavior is associated with |
---|---|
child | the child view of the CoordinatorLayout this Behavior is associated with |
insets | the new window insets. |
Respond to a change in a child's dependent view
This method is called whenever a dependent view changes in size or position outside of the standard layout flow. A Behavior may use this method to appropriately update the child view in response.
A view's dependency is determined by
layoutDependsOn(CoordinatorLayout, android.view.View, android.view.View)
or
if child
has set another view as it's anchor.
Note that if a Behavior changes the layout of a child via this method, it should
also be able to reconstruct the correct position in
onLayoutChild
.
onDependentViewChanged
will not be called during normal layout since
the layout of each child view will always happen in dependency order.
If the Behavior changes the child view's size or position, it should return true. The default implementation returns false.
parent | the parent view of the given child |
---|---|
child | the child view to manipulate |
dependency | the dependent view that changed |
Respond to a child's dependent view being removed.
This method is called after a dependent view has been removed from the parent. A Behavior may use this method to appropriately update the child view in response.
A view's dependency is determined by
layoutDependsOn(CoordinatorLayout, android.view.View, android.view.View)
or
if child
has set another view as it's anchor.
parent | the parent view of the given child |
---|---|
child | the child view to manipulate |
dependency | the dependent view that has been removed |
Respond to CoordinatorLayout touch events before they are dispatched to child views.
Behaviors can use this to monitor inbound touch events until one decides to intercept the rest of the event stream to take an action on its associated child view. This method will return false until it detects the proper intercept conditions, then return true once those conditions have occurred.
Once a Behavior intercepts touch events, the rest of the event stream will
be sent to the onTouchEvent(CoordinatorLayout, V, MotionEvent)
method.
The default implementation of this method always returns false.
parent | the parent view currently receiving this touch event |
---|---|
child | the child view associated with this Behavior |
ev | the MotionEvent describing the touch event being processed |
Called when the parent CoordinatorLayout is about the lay out the given child view.
This method can be used to perform custom or modified layout of a child view
in place of the default child layout behavior. The Behavior's implementation can
delegate to the standard CoordinatorLayout measurement behavior by calling
parent.onMeasureChild
.
If a Behavior implements
onDependentViewChanged(CoordinatorLayout, android.view.View, android.view.View)
to change the position of a view in response to a dependent view changing, it
should also implement onLayoutChild
in such a way that respects those
dependent views. onLayoutChild
will always be called for a dependent view
after its dependency has been laid out.
parent | the parent CoordinatorLayout |
---|---|
child | child view to lay out |
layoutDirection | the resolved layout direction for the CoordinatorLayout, such as
LAYOUT_DIRECTION_LTR or
LAYOUT_DIRECTION_RTL . |
Called when the parent CoordinatorLayout is about to measure the given child view.
This method can be used to perform custom or modified measurement of a child view
in place of the default child measurement behavior. The Behavior's implementation
can delegate to the standard CoordinatorLayout measurement behavior by calling
parent.onMeasureChild
.
parent | the parent CoordinatorLayout |
---|---|
child | the child to measure |
parentWidthMeasureSpec | the width requirements for this view |
widthUsed | extra space that has been used up by the parent horizontally (possibly by other children of the parent) |
parentHeightMeasureSpec | the height requirements for this view |
heightUsed | extra space that has been used up by the parent vertically (possibly by other children of the parent) |
Called when a nested scrolling child is starting a fling or an action that would be a fling.
Any Behavior associated with the direct child of the CoordinatorLayout may elect
to accept the nested scroll as part of onStartNestedScroll(CoordinatorLayout, V, View, View, int)
. Each Behavior
that returned true will receive subsequent nested scroll events for that nested scroll.
onNestedFling
is called when the current nested scrolling child view
detects the proper conditions for a fling. It reports if the child itself consumed
the fling. If it did not, the child is expected to show some sort of overscroll
indication. This method should return true if it consumes the fling, so that a child
that did not itself take an action in response can choose not to show an overfling
indication.
coordinatorLayout | the CoordinatorLayout parent of the view this Behavior is associated with |
---|---|
child | the child view of the CoordinatorLayout this Behavior is associated with |
target | the descendant view of the CoordinatorLayout performing the nested scroll |
velocityX | horizontal velocity of the attempted fling |
velocityY | vertical velocity of the attempted fling |
consumed | true if the nested child view consumed the fling |
Called when a nested scrolling child is about to start a fling.
Any Behavior associated with the direct child of the CoordinatorLayout may elect
to accept the nested scroll as part of onStartNestedScroll(CoordinatorLayout, V, View, View, int)
. Each Behavior
that returned true will receive subsequent nested scroll events for that nested scroll.
onNestedPreFling
is called when the current nested scrolling child view
detects the proper conditions for a fling, but it has not acted on it yet. A
Behavior can return true to indicate that it consumed the fling. If at least one
Behavior returns true, the fling should not be acted upon by the child.
coordinatorLayout | the CoordinatorLayout parent of the view this Behavior is associated with |
---|---|
child | the child view of the CoordinatorLayout this Behavior is associated with |
target | the descendant view of the CoordinatorLayout performing the nested scroll |
velocityX | horizontal velocity of the attempted fling |
velocityY | vertical velocity of the attempted fling |
Called when a nested scroll in progress is about to update, before the target has consumed any of the scrolled distance.
Any Behavior associated with the direct child of the CoordinatorLayout may elect
to accept the nested scroll as part of onStartNestedScroll(CoordinatorLayout, V, View, View, int)
. Each Behavior
that returned true will receive subsequent nested scroll events for that nested scroll.
onNestedPreScroll
is called each time the nested scroll is updated
by the nested scrolling child, before the nested scrolling child has consumed the scroll
distance itself. Each Behavior responding to the nested scroll will receive the
same values. The CoordinatorLayout will report as consumed the maximum number
of pixels in either direction that any Behavior responding to the nested scroll reported
as consumed.
coordinatorLayout | the CoordinatorLayout parent of the view this Behavior is associated with |
---|---|
child | the child view of the CoordinatorLayout this Behavior is associated with |
target | the descendant view of the CoordinatorLayout performing the nested scroll |
dx | the raw horizontal number of pixels that the user attempted to scroll |
dy | the raw vertical number of pixels that the user attempted to scroll |
consumed | out parameter. consumed[0] should be set to the distance of dx that was consumed, consumed[1] should be set to the distance of dy that was consumed |
Called when a nested scroll in progress has updated and the target has scrolled or attempted to scroll.
Any Behavior associated with the direct child of the CoordinatorLayout may elect
to accept the nested scroll as part of onStartNestedScroll(CoordinatorLayout, V, View, View, int)
. Each Behavior
that returned true will receive subsequent nested scroll events for that nested scroll.
onNestedScroll
is called each time the nested scroll is updated by the
nested scrolling child, with both consumed and unconsumed components of the scroll
supplied in pixels. Each Behavior responding to the nested scroll will receive the
same values.
coordinatorLayout | the CoordinatorLayout parent of the view this Behavior is associated with |
---|---|
child | the child view of the CoordinatorLayout this Behavior is associated with |
target | the descendant view of the CoordinatorLayout performing the nested scroll |
dxConsumed | horizontal pixels consumed by the target's own scrolling operation |
dyConsumed | vertical pixels consumed by the target's own scrolling operation |
dxUnconsumed | horizontal pixels not consumed by the target's own scrolling operation, but requested by the user |
dyUnconsumed | vertical pixels not consumed by the target's own scrolling operation, but requested by the user |
Called when a nested scroll has been accepted by the CoordinatorLayout.
Any Behavior associated with any direct child of the CoordinatorLayout may elect
to accept the nested scroll as part of onStartNestedScroll(CoordinatorLayout, V, View, View, int)
. Each Behavior
that returned true will receive subsequent nested scroll events for that nested scroll.
coordinatorLayout | the CoordinatorLayout parent of the view this Behavior is associated with |
---|---|
child | the child view of the CoordinatorLayout this Behavior is associated with |
directTargetChild | the child view of the CoordinatorLayout that either is or contains the target of the nested scroll operation |
target | the descendant view of the CoordinatorLayout initiating the nested scroll |
nestedScrollAxes | the axes that this nested scroll applies to. See
SCROLL_AXIS_HORIZONTAL ,
SCROLL_AXIS_VERTICAL |
Hook allowing a behavior to re-apply a representation of its internal state that had
previously been generated by onSaveInstanceState(CoordinatorLayout, V)
. This function will never
be called with a null state.
parent | the parent CoordinatorLayout |
---|---|
child | child view to restore from |
state | The frozen state that had previously been returned by
onSaveInstanceState(CoordinatorLayout, V) . |
Hook allowing a behavior to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later.
Behavior state is only saved when both the parent CoordinatorLayout
and
a view using this behavior have valid IDs set.
parent | the parent CoordinatorLayout |
---|---|
child | child view to restore from |
Called when a descendant of the CoordinatorLayout attempts to initiate a nested scroll.
Any Behavior associated with any direct child of the CoordinatorLayout may respond to this event and return true to indicate that the CoordinatorLayout should act as a nested scrolling parent for this scroll. Only Behaviors that return true from this method will receive subsequent nested scroll events.
coordinatorLayout | the CoordinatorLayout parent of the view this Behavior is associated with |
---|---|
child | the child view of the CoordinatorLayout this Behavior is associated with |
directTargetChild | the child view of the CoordinatorLayout that either is or contains the target of the nested scroll operation |
target | the descendant view of the CoordinatorLayout initiating the nested scroll |
nestedScrollAxes | the axes that this nested scroll applies to. See
SCROLL_AXIS_HORIZONTAL ,
SCROLL_AXIS_VERTICAL |
Called when a nested scroll has ended.
Any Behavior associated with any direct child of the CoordinatorLayout may elect
to accept the nested scroll as part of onStartNestedScroll(CoordinatorLayout, V, View, View, int)
. Each Behavior
that returned true will receive subsequent nested scroll events for that nested scroll.
onStopNestedScroll
marks the end of a single nested scroll event
sequence. This is a good place to clean up any state related to the nested scroll.
coordinatorLayout | the CoordinatorLayout parent of the view this Behavior is associated with |
---|---|
child | the child view of the CoordinatorLayout this Behavior is associated with |
target | the descendant view of the CoordinatorLayout that initiated the nested scroll |
Respond to CoordinatorLayout touch events after this Behavior has started
intercepting
them.
Behaviors may intercept touch events in order to help the CoordinatorLayout manipulate its child views. For example, a Behavior may allow a user to drag a UI pane open or closed. This method should perform actual mutations of view layout state.
parent | the parent view currently receiving this touch event |
---|---|
child | the child view associated with this Behavior |
ev | the MotionEvent describing the touch event being processed |
Associate a Behavior-specific tag object with the given child view. This object will be stored with the child view's LayoutParams.
child | child view to set tag with |
---|---|
tag | tag object to set |