public static class AppBarLayout.Behavior extends CoordinatorLayout.Behavior<V>
AppBarLayout.Behavior
for AppBarLayout
. Implements the necessary nested
scroll handling with offsetting.Modifier and Type | Class and Description |
---|---|
static class |
AppBarLayout.Behavior.DragCallback
Callback to allow control over any
AppBarLayout dragging. |
protected static class |
AppBarLayout.Behavior.SavedState |
Constructor and Description |
---|
Behavior() |
Behavior(Context context,
AttributeSet attrs) |
Modifier and Type | Method and Description |
---|---|
int |
getLeftAndRightOffset() |
int |
getTopAndBottomOffset() |
protected void |
layoutChild(CoordinatorLayout parent,
V child,
int layoutDirection) |
boolean |
onInterceptTouchEvent(CoordinatorLayout parent,
V child,
MotionEvent ev)
Respond to CoordinatorLayout touch events before they are dispatched to child views.
|
boolean |
onLayoutChild(CoordinatorLayout parent,
AppBarLayout abl,
int layoutDirection)
Called when the parent CoordinatorLayout is about the lay out the given child view.
|
boolean |
onMeasureChild(CoordinatorLayout parent,
AppBarLayout child,
int parentWidthMeasureSpec,
int widthUsed,
int parentHeightMeasureSpec,
int heightUsed)
Called when the parent CoordinatorLayout is about to measure the given child view.
|
boolean |
onNestedFling(CoordinatorLayout coordinatorLayout,
AppBarLayout child,
View target,
float velocityX,
float velocityY,
boolean consumed)
Called when a nested scrolling child is starting a fling or an action that would
be a fling.
|
void |
onNestedPreScroll(CoordinatorLayout coordinatorLayout,
AppBarLayout child,
View target,
int dx,
int dy,
int[] consumed)
Called when a nested scroll in progress is about to update, before the target has
consumed any of the scrolled distance.
|
void |
onNestedScroll(CoordinatorLayout coordinatorLayout,
AppBarLayout child,
View target,
int dxConsumed,
int dyConsumed,
int dxUnconsumed,
int dyUnconsumed)
Called when a nested scroll in progress has updated and the target has scrolled or
attempted to scroll.
|
void |
onRestoreInstanceState(CoordinatorLayout parent,
AppBarLayout appBarLayout,
Parcelable state)
Hook allowing a behavior to re-apply a representation of its internal state that had
previously been generated by
CoordinatorLayout.Behavior.onSaveInstanceState(android.support.design.widget.CoordinatorLayout, V) . |
Parcelable |
onSaveInstanceState(CoordinatorLayout parent,
AppBarLayout abl)
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.
|
boolean |
onStartNestedScroll(CoordinatorLayout parent,
AppBarLayout child,
View directTargetChild,
View target,
int nestedScrollAxes)
Called when a descendant of the CoordinatorLayout attempts to initiate a nested scroll.
|
void |
onStopNestedScroll(CoordinatorLayout coordinatorLayout,
AppBarLayout abl,
View target)
Called when a nested scroll has ended.
|
boolean |
onTouchEvent(CoordinatorLayout parent,
V child,
MotionEvent ev)
Respond to CoordinatorLayout touch events after this Behavior has started
intercepting them. |
void |
setDragCallback(AppBarLayout.Behavior.DragCallback callback)
Set a callback to control any
AppBarLayout dragging. |
boolean |
setLeftAndRightOffset(int offset) |
boolean |
setTopAndBottomOffset(int offset) |
blocksInteractionBelow, getInsetDodgeRect, getScrimColor, getScrimOpacity, getTag, isDirty, layoutDependsOn, onApplyWindowInsets, onAttachedToLayoutParams, onDependentViewChanged, onDependentViewRemoved, onDetachedFromLayoutParams, onNestedPreFling, onNestedScrollAccepted, onRequestChildRectangleOnScreen, setTag
public Behavior()
public Behavior(Context context, AttributeSet attrs)
public boolean onStartNestedScroll(CoordinatorLayout parent, AppBarLayout child, View directTargetChild, View target, int nestedScrollAxes)
CoordinatorLayout.Behavior
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.
onStartNestedScroll
in class CoordinatorLayout.Behavior<AppBarLayout>
parent
- the CoordinatorLayout parent of the view this Behavior is
associated withchild
- the child view of the CoordinatorLayout this Behavior is associated withdirectTargetChild
- the child view of the CoordinatorLayout that either is or
contains the target of the nested scroll operationtarget
- the descendant view of the CoordinatorLayout initiating the nested scrollnestedScrollAxes
- the axes that this nested scroll applies to. See
ViewCompat.SCROLL_AXIS_HORIZONTAL
,
ViewCompat.SCROLL_AXIS_VERTICAL
NestedScrollingParent.onStartNestedScroll(View, View, int)
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, int dx, int dy, int[] consumed)
CoordinatorLayout.Behavior
Any Behavior associated with the direct child of the CoordinatorLayout may elect
to accept the nested scroll as part of CoordinatorLayout.Behavior.onStartNestedScroll(android.support.design.widget.CoordinatorLayout, V, android.view.View, android.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.
onNestedPreScroll
in class CoordinatorLayout.Behavior<AppBarLayout>
coordinatorLayout
- the CoordinatorLayout parent of the view this Behavior is
associated withchild
- the child view of the CoordinatorLayout this Behavior is associated withtarget
- the descendant view of the CoordinatorLayout performing the nested scrolldx
- the raw horizontal number of pixels that the user attempted to scrolldy
- the raw vertical number of pixels that the user attempted to scrollconsumed
- 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 consumedNestedScrollingParent.onNestedPreScroll(View, int, int, int[])
public void onNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed)
CoordinatorLayout.Behavior
Any Behavior associated with the direct child of the CoordinatorLayout may elect
to accept the nested scroll as part of CoordinatorLayout.Behavior.onStartNestedScroll(android.support.design.widget.CoordinatorLayout, V, android.view.View, android.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.
onNestedScroll
in class CoordinatorLayout.Behavior<AppBarLayout>
coordinatorLayout
- the CoordinatorLayout parent of the view this Behavior is
associated withchild
- the child view of the CoordinatorLayout this Behavior is associated withtarget
- the descendant view of the CoordinatorLayout performing the nested scrolldxConsumed
- horizontal pixels consumed by the target's own scrolling operationdyConsumed
- vertical pixels consumed by the target's own scrolling operationdxUnconsumed
- horizontal pixels not consumed by the target's own scrolling
operation, but requested by the userdyUnconsumed
- vertical pixels not consumed by the target's own scrolling operation,
but requested by the userNestedScrollingParent.onNestedScroll(View, int, int, int, int)
public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout abl, View target)
CoordinatorLayout.Behavior
Any Behavior associated with any direct child of the CoordinatorLayout may elect
to accept the nested scroll as part of CoordinatorLayout.Behavior.onStartNestedScroll(android.support.design.widget.CoordinatorLayout, V, android.view.View, android.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.
onStopNestedScroll
in class CoordinatorLayout.Behavior<AppBarLayout>
coordinatorLayout
- the CoordinatorLayout parent of the view this Behavior is
associated withabl
- the child view of the CoordinatorLayout this Behavior is associated withtarget
- the descendant view of the CoordinatorLayout that initiated
the nested scrollNestedScrollingParent.onStopNestedScroll(View)
public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, float velocityX, float velocityY, boolean consumed)
CoordinatorLayout.Behavior
Any Behavior associated with the direct child of the CoordinatorLayout may elect
to accept the nested scroll as part of CoordinatorLayout.Behavior.onStartNestedScroll(android.support.design.widget.CoordinatorLayout, V, android.view.View, android.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.
onNestedFling
in class CoordinatorLayout.Behavior<AppBarLayout>
coordinatorLayout
- the CoordinatorLayout parent of the view this Behavior is
associated withchild
- the child view of the CoordinatorLayout this Behavior is associated withtarget
- the descendant view of the CoordinatorLayout performing the nested scrollvelocityX
- horizontal velocity of the attempted flingvelocityY
- vertical velocity of the attempted flingconsumed
- true if the nested child view consumed the flingNestedScrollingParent.onNestedFling(View, float, float, boolean)
public void setDragCallback(@Nullable AppBarLayout.Behavior.DragCallback callback)
AppBarLayout
dragging.callback
- the callback to use, or null
to use the default behavior.public boolean onMeasureChild(CoordinatorLayout parent, AppBarLayout child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed)
CoordinatorLayout.Behavior
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
.
onMeasureChild
in class CoordinatorLayout.Behavior<AppBarLayout>
parent
- the parent CoordinatorLayoutchild
- the child to measureparentWidthMeasureSpec
- the width requirements for this viewwidthUsed
- extra space that has been used up by the parent
horizontally (possibly by other children of the parent)parentHeightMeasureSpec
- the height requirements for this viewheightUsed
- extra space that has been used up by the parent
vertically (possibly by other children of the parent)public boolean onLayoutChild(CoordinatorLayout parent, AppBarLayout abl, int layoutDirection)
CoordinatorLayout.Behavior
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
CoordinatorLayout.Behavior.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 CoordinatorLayoutabl
- child view to lay outlayoutDirection
- the resolved layout direction for the CoordinatorLayout, such as
ViewCompat.LAYOUT_DIRECTION_LTR
or
ViewCompat.LAYOUT_DIRECTION_RTL
.public Parcelable onSaveInstanceState(CoordinatorLayout parent, AppBarLayout abl)
CoordinatorLayout.Behavior
Behavior state is only saved when both the parent CoordinatorLayout
and
a view using this behavior have valid IDs set.
onSaveInstanceState
in class CoordinatorLayout.Behavior<AppBarLayout>
parent
- the parent CoordinatorLayoutabl
- child view to restore fromCoordinatorLayout.onRestoreInstanceState(android.os.Parcelable)
,
View.onSaveInstanceState()
public void onRestoreInstanceState(CoordinatorLayout parent, AppBarLayout appBarLayout, Parcelable state)
CoordinatorLayout.Behavior
CoordinatorLayout.Behavior.onSaveInstanceState(android.support.design.widget.CoordinatorLayout, V)
. This function will never
be called with a null state.onRestoreInstanceState
in class CoordinatorLayout.Behavior<AppBarLayout>
parent
- the parent CoordinatorLayoutappBarLayout
- child view to restore fromstate
- The frozen state that had previously been returned by
CoordinatorLayout.Behavior.onSaveInstanceState(android.support.design.widget.CoordinatorLayout, V)
.CoordinatorLayout.onSaveInstanceState()
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev)
CoordinatorLayout.Behavior
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 CoordinatorLayout.Behavior.onTouchEvent(android.support.design.widget.CoordinatorLayout, V, android.view.MotionEvent)
method.
The default implementation of this method always returns false.
onInterceptTouchEvent
in class CoordinatorLayout.Behavior<V extends View>
parent
- the parent view currently receiving this touch eventchild
- the child view associated with this Behaviorev
- the MotionEvent describing the touch event being processedpublic boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev)
CoordinatorLayout.Behavior
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.
onTouchEvent
in class CoordinatorLayout.Behavior<V extends View>
parent
- the parent view currently receiving this touch eventchild
- the child view associated with this Behaviorev
- the MotionEvent describing the touch event being processedprotected void layoutChild(CoordinatorLayout parent, V child, int layoutDirection)
public boolean setTopAndBottomOffset(int offset)
public boolean setLeftAndRightOffset(int offset)
public int getTopAndBottomOffset()
public int getLeftAndRightOffset()