Behavior
abstract class Behavior<V : View!>
kotlin.Any | |
↳ | androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior |
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.
Summary
Public constructors |
|
---|---|
<init>() Default constructor for instantiating Behaviors. |
|
<init>(context: Context!, attrs: AttributeSet!) Default constructor for inflating Behaviors from layout. |
Public methods |
|
---|---|
open Boolean |
blocksInteractionBelow(@NonNull parent: CoordinatorLayout, @NonNull child: V) Determine whether interaction with views behind the given child in the child order should be blocked. |
open Boolean |
getInsetDodgeRect(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull rect: Rect) Called when a view is set to dodge view insets. |
open Int |
getScrimColor(@NonNull parent: CoordinatorLayout, @NonNull child: V) Supply a scrim color that will be painted behind the associated child view. |
open Float |
getScrimOpacity(@NonNull parent: CoordinatorLayout, @NonNull child: V) Determine the current opacity of the scrim behind a given child view |
open static Any? |
Get the behavior-specific tag object with the given child view. |
open Boolean |
layoutDependsOn(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull dependency: View) Determine whether the supplied child view has another specific sibling view as a layout dependency. |
open WindowInsetsCompat |
onApplyWindowInsets(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull insets: WindowInsetsCompat) Called when the window insets have changed. |
open Unit |
onAttachedToLayoutParams(@NonNull params: CoordinatorLayout.LayoutParams) Called when the Behavior has been attached to a LayoutParams instance. |
open Boolean |
onDependentViewChanged(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull dependency: View) Respond to a change in a child's dependent view |
open Unit |
onDependentViewRemoved(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull dependency: View) Respond to a child's dependent view being removed. |
open Unit |
Called when the Behavior has been detached from its holding LayoutParams instance. |
open Boolean |
onInterceptTouchEvent(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull ev: MotionEvent) Respond to CoordinatorLayout touch events before they are dispatched to child views. |
open Boolean |
onLayoutChild(@NonNull parent: CoordinatorLayout, @NonNull child: V, layoutDirection: Int) Called when the parent CoordinatorLayout is about the lay out the given child view. |
open Boolean |
onMeasureChild(@NonNull parent: CoordinatorLayout, @NonNull child: V, parentWidthMeasureSpec: Int, widthUsed: Int, parentHeightMeasureSpec: Int, heightUsed: Int) Called when the parent CoordinatorLayout is about to measure the given child view. |
open Boolean |
onNestedFling(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, velocityX: Float, velocityY: Float, consumed: Boolean) Called when a nested scrolling child is starting a fling or an action that would be a fling. |
open Boolean |
onNestedPreFling(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, velocityX: Float, velocityY: Float) Called when a nested scrolling child is about to start a fling. |
open Unit |
onNestedPreScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, dx: Int, dy: Int, @NonNull consumed: IntArray) |
open Unit |
onNestedPreScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, dx: Int, dy: Int, @NonNull consumed: IntArray, type: Int) Called when a nested scroll in progress is about to update, before the target has consumed any of the scrolled distance. |
open Unit |
onNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int) |
open Unit |
onNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, type: Int) |
open Unit |
onNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, type: Int, @NonNull consumed: IntArray) Called when a nested scroll in progress has updated and the target has scrolled or attempted to scroll. |
open Unit |
onNestedScrollAccepted(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull directTargetChild: View, @NonNull target: View, axes: Int) |
open Unit |
onNestedScrollAccepted(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull directTargetChild: View, @NonNull target: View, axes: Int, type: Int) Called when a nested scroll has been accepted by the CoordinatorLayout. |
open Boolean |
onRequestChildRectangleOnScreen(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull rectangle: Rect, immediate: Boolean) Called when a child of the view associated with this behavior wants a particular rectangle to be positioned onto the screen. |
open Unit |
onRestoreInstanceState(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull state: Parcelable) Hook allowing a behavior to re-apply a representation of its internal state that had previously been generated by |
open Parcelable? |
onSaveInstanceState(@NonNull parent: CoordinatorLayout, @NonNull child: 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. |
open Boolean |
onStartNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull directTargetChild: View, @NonNull target: View, axes: Int) |
open Boolean |
onStartNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull directTargetChild: View, @NonNull target: View, axes: Int, type: Int) Called when a descendant of the CoordinatorLayout attempts to initiate a nested scroll. |
open Unit |
onStopNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View) |
open Unit |
onStopNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, type: Int) Called when a nested scroll has ended. |
open Boolean |
onTouchEvent(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull ev: MotionEvent) Respond to CoordinatorLayout touch events after this Behavior has started |
open static Unit |
Associate a Behavior-specific tag object with the given child view. |
Public constructors
<init>
Behavior()
Default constructor for instantiating Behaviors.
<init>
Behavior(context: Context!, attrs: AttributeSet!)
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.
Parameters | |
---|---|
context |
Context!: |
attrs |
Context!: |
Public methods
blocksInteractionBelow
open fun blocksInteractionBelow(@NonNull parent: CoordinatorLayout, @NonNull child: V): Boolean
Determine whether interaction with views behind the given child in the child order should be blocked.
The default implementation returns true if getScrimOpacity(CoordinatorLayout, View)
would return > 0.0f.
Parameters | |
---|---|
parent |
CoordinatorLayout: the parent view of the given child |
child |
CoordinatorLayout: the child view to test |
Return | |
---|---|
Boolean: true if getScrimOpacity(CoordinatorLayout, View) would return > 0.0f. |
getInsetDodgeRect
open fun getInsetDodgeRect(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull rect: Rect): Boolean
Called when a view is set to dodge view insets.
This method allows a behavior to update the rectangle that should be dodged. The rectangle should be in the parent's coordinate system and within the child's bounds. If not, a IllegalArgumentException
is thrown.
Parameters | |
---|---|
parent |
CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with |
child |
CoordinatorLayout: the child view of the CoordinatorLayout this Behavior is associated with |
rect |
CoordinatorLayout: the rect to update with the dodge rectangle |
Return | |
---|---|
Boolean: true the rect was updated, false if we should use the child's bounds |
getScrimColor
open fun getScrimColor(@NonNull parent: CoordinatorLayout, @NonNull child: V): Int
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 Color#BLACK
.
Parameters | |
---|---|
parent |
CoordinatorLayout: the parent view of the given child |
child |
CoordinatorLayout: the child view above the scrim |
Return | |
---|---|
Int: the desired scrim color in 0xAARRGGBB format. The default return value is Color#BLACK . |
getScrimOpacity
open fun getScrimOpacity(@NonNull parent: CoordinatorLayout, @NonNull child: V): Float
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.
Parameters | |
---|---|
parent |
CoordinatorLayout: the parent view of the given child |
child |
CoordinatorLayout: the child view above the scrim |
Return | |
---|---|
Float: the desired scrim opacity from 0.0f to 1.0f. The default return value is 0.0f. |
getTag
@Nullable open static fun getTag(@NonNull child: View): Any?
Get the behavior-specific tag object with the given child view. This object is stored with the child view's LayoutParams.
Parameters | |
---|---|
child |
View: child view to get tag with |
Return | |
---|---|
Any?: the previously stored tag object |
layoutDependsOn
open fun layoutDependsOn(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull dependency: View): Boolean
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:
- Always lay out this child after the dependent child is laid out, regardless of child order.
- Call
onDependentViewChanged
when the dependency view's layout or position changes.
Parameters | |
---|---|
parent |
CoordinatorLayout: the parent view of the given child |
child |
CoordinatorLayout: the child view to test |
dependency |
CoordinatorLayout: the proposed dependency of child |
Return | |
---|---|
Boolean: true if child's layout depends on the proposed dependency's layout, false otherwise |
onApplyWindowInsets
@NonNull open fun onApplyWindowInsets(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull insets: WindowInsetsCompat): WindowInsetsCompat
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.
Parameters | |
---|---|
coordinatorLayout |
CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with |
child |
CoordinatorLayout: the child view of the CoordinatorLayout this Behavior is associated with |
insets |
CoordinatorLayout: the new window insets. |
Return | |
---|---|
WindowInsetsCompat: The insets supplied, minus any insets that were consumed |
onAttachedToLayoutParams
open fun onAttachedToLayoutParams(@NonNull params: CoordinatorLayout.LayoutParams): Unit
Called when the Behavior has been attached to a LayoutParams instance.
This will be called after the LayoutParams has been instantiated and can be modified.
Parameters | |
---|---|
params |
CoordinatorLayout.LayoutParams: the LayoutParams instance that this Behavior has been attached to |
onDependentViewChanged
open fun onDependentViewChanged(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull dependency: View): Boolean
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, 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.
Parameters | |
---|---|
parent |
CoordinatorLayout: the parent view of the given child |
child |
CoordinatorLayout: the child view to manipulate |
dependency |
CoordinatorLayout: the dependent view that changed |
Return | |
---|---|
Boolean: true if the Behavior changed the child view's size or position, false otherwise |
onDependentViewRemoved
open fun onDependentViewRemoved(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull dependency: View): Unit
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, View, View)
or if child
has set another view as it's anchor.
Parameters | |
---|---|
parent |
CoordinatorLayout: the parent view of the given child |
child |
CoordinatorLayout: the child view to manipulate |
dependency |
CoordinatorLayout: the dependent view that has been removed |
onDetachedFromLayoutParams
open fun onDetachedFromLayoutParams(): Unit
Called when the Behavior has been detached from its holding LayoutParams instance.
This will only be called if the Behavior has been explicitly removed from the LayoutParams instance via LayoutParams#setBehavior(Behavior)
. It will not be called if the associated view is removed from the CoordinatorLayout or similar.
onInterceptTouchEvent
open fun onInterceptTouchEvent(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull ev: MotionEvent): Boolean
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
method.
This method will be called regardless of the visibility of the associated child of the behavior. If you only wish to handle touch events when the child is visible, you should add a check to View#isShown()
on the given child.
The default implementation of this method always returns false.
Parameters | |
---|---|
parent |
CoordinatorLayout: the parent view currently receiving this touch event |
child |
CoordinatorLayout: the child view associated with this Behavior |
ev |
CoordinatorLayout: the MotionEvent describing the touch event being processed |
Return | |
---|---|
Boolean: true if this Behavior would like to intercept and take over the event stream. The default always returns false. |
onLayoutChild
open fun onLayoutChild(@NonNull parent: CoordinatorLayout, @NonNull child: V, layoutDirection: Int): Boolean
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.onLayoutChild
.
If a Behavior implements onDependentViewChanged(CoordinatorLayout, 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.
Parameters | |
---|---|
parent |
CoordinatorLayout: the parent CoordinatorLayout |
child |
CoordinatorLayout: child view to lay out |
layoutDirection |
CoordinatorLayout: the resolved layout direction for the CoordinatorLayout, such as ViewCompat#LAYOUT_DIRECTION_LTR or ViewCompat#LAYOUT_DIRECTION_RTL . |
Return | |
---|---|
Boolean: true if the Behavior performed layout of the child view, false to request default layout behavior |
onMeasureChild
open fun onMeasureChild(@NonNull parent: CoordinatorLayout, @NonNull child: V, parentWidthMeasureSpec: Int, widthUsed: Int, parentHeightMeasureSpec: Int, heightUsed: Int): Boolean
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
.
Parameters | |
---|---|
parent |
CoordinatorLayout: the parent CoordinatorLayout |
child |
CoordinatorLayout: the child to measure |
parentWidthMeasureSpec |
CoordinatorLayout: the width requirements for this view |
widthUsed |
CoordinatorLayout: extra space that has been used up by the parent horizontally (possibly by other children of the parent) |
parentHeightMeasureSpec |
CoordinatorLayout: the height requirements for this view |
heightUsed |
CoordinatorLayout: extra space that has been used up by the parent vertically (possibly by other children of the parent) |
Return | |
---|---|
Boolean: true if the Behavior measured the child view, false if the CoordinatorLayout should perform its default measurement |
onNestedFling
open fun onNestedFling(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, velocityX: Float, velocityY: Float, consumed: Boolean): Boolean
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
. 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.
Parameters | |
---|---|
coordinatorLayout |
CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with |
child |
CoordinatorLayout: the child view of the CoordinatorLayout this Behavior is associated with |
target |
CoordinatorLayout: the descendant view of the CoordinatorLayout performing the nested scroll |
velocityX |
CoordinatorLayout: horizontal velocity of the attempted fling |
velocityY |
CoordinatorLayout: vertical velocity of the attempted fling |
consumed |
CoordinatorLayout: true if the nested child view consumed the fling |
Return | |
---|---|
Boolean: true if the Behavior consumed the fling |
onNestedPreFling
open fun onNestedPreFling(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, velocityX: Float, velocityY: Float): Boolean
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
. 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.
Parameters | |
---|---|
coordinatorLayout |
CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with |
child |
CoordinatorLayout: the child view of the CoordinatorLayout this Behavior is associated with |
target |
CoordinatorLayout: the descendant view of the CoordinatorLayout performing the nested scroll |
velocityX |
CoordinatorLayout: horizontal velocity of the attempted fling |
velocityY |
CoordinatorLayout: vertical velocity of the attempted fling |
Return | |
---|---|
Boolean: true if the Behavior consumed the fling |
onNestedPreScroll
open funonNestedPreScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, dx: Int, dy: Int, @NonNull consumed: IntArray): Unit
Deprecated: You should now override onNestedPreScroll(CoordinatorLayout, View, View, int, int, int[], int)
. This method will still continue to be called if the type is ViewCompat#TYPE_TOUCH
.
onNestedPreScroll
open fun onNestedPreScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, dx: Int, dy: Int, @NonNull consumed: IntArray, type: Int): Unit
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
. 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.
Parameters | |
---|---|
coordinatorLayout |
CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with |
child |
CoordinatorLayout: the child view of the CoordinatorLayout this Behavior is associated with |
target |
CoordinatorLayout: the descendant view of the CoordinatorLayout performing the nested scroll |
dx |
CoordinatorLayout: the raw horizontal number of pixels that the user attempted to scroll |
dy |
CoordinatorLayout: the raw vertical number of pixels that the user attempted to scroll |
consumed |
CoordinatorLayout: 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 |
type |
CoordinatorLayout: the type of input which cause this scroll event |
onNestedScroll
open funonNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int): Unit
Deprecated: You should now override onNestedScroll(CoordinatorLayout, View, View, int, int, int, int, int, int[])
. This method will still continue to be called if neither onNestedScroll(CoordinatorLayout, View, View, int, int, int, int, int, int[])
nor onNestedScroll(View, int, int, int, int, int)
are overridden and the type is ViewCompat#TYPE_TOUCH
.
onNestedScroll
open funonNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, type: Int): Unit
Deprecated: You should now override onNestedScroll(CoordinatorLayout, View, View, int, int, int, int, int, int[])
. This method will still continue to be called if onNestedScroll(CoordinatorLayout, View, View, int, int, int, int, int, int[])
is not overridden.
onNestedScroll
open fun onNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, type: Int, @NonNull consumed: IntArray): Unit
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
. 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.
Parameters | |
---|---|
coordinatorLayout |
CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with |
child |
CoordinatorLayout: the child view of the CoordinatorLayout this Behavior is associated with |
target |
CoordinatorLayout: the descendant view of the CoordinatorLayout performing the nested scroll |
dxConsumed |
CoordinatorLayout: horizontal pixels consumed by the target's own scrolling operation |
dyConsumed |
CoordinatorLayout: vertical pixels consumed by the target's own scrolling operation |
dxUnconsumed |
CoordinatorLayout: horizontal pixels not consumed by the target's own scrolling operation, but requested by the user |
dyUnconsumed |
CoordinatorLayout: vertical pixels not consumed by the target's own scrolling operation, but requested by the user |
type |
CoordinatorLayout: the type of input which cause this scroll event |
consumed |
CoordinatorLayout: output. Upon this method returning, should contain the scroll distances consumed by this Behavior |
onNestedScrollAccepted
open funonNestedScrollAccepted(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull directTargetChild: View, @NonNull target: View, axes: Int): Unit
Deprecated: You should now override onNestedScrollAccepted(CoordinatorLayout, View, View, View, int, int)
. This method will still continue to be called if the type is ViewCompat#TYPE_TOUCH
.
onNestedScrollAccepted
open fun onNestedScrollAccepted(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull directTargetChild: View, @NonNull target: View, axes: Int, type: Int): Unit
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
. Each Behavior that returned true will receive subsequent nested scroll events for that nested scroll.
Parameters | |
---|---|
coordinatorLayout |
CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with |
child |
CoordinatorLayout: the child view of the CoordinatorLayout this Behavior is associated with |
directTargetChild |
CoordinatorLayout: the child view of the CoordinatorLayout that either is or contains the target of the nested scroll operation |
target |
CoordinatorLayout: the descendant view of the CoordinatorLayout initiating the nested scroll |
axes |
CoordinatorLayout: the axes that this nested scroll applies to. See ViewCompat#SCROLL_AXIS_HORIZONTAL , ViewCompat#SCROLL_AXIS_VERTICAL |
type |
CoordinatorLayout: the type of input which cause this scroll event |
onRequestChildRectangleOnScreen
open fun onRequestChildRectangleOnScreen(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull rectangle: Rect, immediate: Boolean): Boolean
Called when a child of the view associated with this behavior wants a particular rectangle to be positioned onto the screen.
The contract for this method is the same as ViewParent#requestChildRectangleOnScreen(View, Rect, boolean)
.
Parameters | |
---|---|
coordinatorLayout |
CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with |
child |
CoordinatorLayout: the child view of the CoordinatorLayout this Behavior is associated with |
rectangle |
CoordinatorLayout: The rectangle which the child wishes to be on the screen in the child's coordinates |
immediate |
CoordinatorLayout: true to forbid animated or delayed scrolling, false otherwise |
Return | |
---|---|
Boolean: true if the Behavior handled the request |
onRestoreInstanceState
open fun onRestoreInstanceState(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull state: Parcelable): Unit
Hook allowing a behavior to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState
. This function will never be called with a null state.
Parameters | |
---|---|
parent |
CoordinatorLayout: the parent CoordinatorLayout |
child |
CoordinatorLayout: child view to restore from |
state |
CoordinatorLayout: The frozen state that had previously been returned by onSaveInstanceState . |
See Also
onSaveInstanceState
@Nullable open fun onSaveInstanceState(@NonNull parent: CoordinatorLayout, @NonNull child: V): Parcelable?
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.
Parameters | |
---|---|
parent |
CoordinatorLayout: the parent CoordinatorLayout |
child |
CoordinatorLayout: child view to restore from |
Return | |
---|---|
Parcelable?: Returns a Parcelable object containing the behavior's current dynamic state. |
onStartNestedScroll
open funonStartNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull directTargetChild: View, @NonNull target: View, axes: Int): Boolean
Deprecated: You should now override onStartNestedScroll(CoordinatorLayout, View, View, View, int, int)
. This method will still continue to be called if the type is ViewCompat#TYPE_TOUCH
.
onStartNestedScroll
open fun onStartNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull directTargetChild: View, @NonNull target: View, axes: Int, type: Int): Boolean
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.
Parameters | |
---|---|
coordinatorLayout |
CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with |
child |
CoordinatorLayout: the child view of the CoordinatorLayout this Behavior is associated with |
directTargetChild |
CoordinatorLayout: the child view of the CoordinatorLayout that either is or contains the target of the nested scroll operation |
target |
CoordinatorLayout: the descendant view of the CoordinatorLayout initiating the nested scroll |
axes |
CoordinatorLayout: the axes that this nested scroll applies to. See ViewCompat#SCROLL_AXIS_HORIZONTAL , ViewCompat#SCROLL_AXIS_VERTICAL |
type |
CoordinatorLayout: the type of input which cause this scroll event |
Return | |
---|---|
Boolean: true if the Behavior wishes to accept this nested scroll |
onStopNestedScroll
open funonStopNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View): Unit
Deprecated: You should now override onStopNestedScroll(CoordinatorLayout, View, View, int)
. This method will still continue to be called if the type is ViewCompat#TYPE_TOUCH
.
onStopNestedScroll
open fun onStopNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, type: Int): Unit
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
. 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.
Parameters | |
---|---|
coordinatorLayout |
CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with |
child |
CoordinatorLayout: the child view of the CoordinatorLayout this Behavior is associated with |
target |
CoordinatorLayout: the descendant view of the CoordinatorLayout that initiated the nested scroll |
type |
CoordinatorLayout: the type of input which cause this scroll event |
onTouchEvent
open fun onTouchEvent(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull ev: MotionEvent): Boolean
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.
This method will be called regardless of the visibility of the associated child of the behavior. If you only wish to handle touch events when the child is visible, you should add a check to View#isShown()
on the given child.
Parameters | |
---|---|
parent |
CoordinatorLayout: the parent view currently receiving this touch event |
child |
CoordinatorLayout: the child view associated with this Behavior |
ev |
CoordinatorLayout: the MotionEvent describing the touch event being processed |
Return | |
---|---|
Boolean: true if this Behavior handled this touch event and would like to continue receiving events in this stream. The default always returns false. |