Most visited

Recently visited

AppBarLayout.Behavior

public static class AppBarLayout.Behavior
extends Behavior<AppBarLayout>

java.lang.Object
   ↳ android.support.design.widget.CoordinatorLayout.Behavior<android.support.design.widget.AppBarLayout>
     ↳ android.support.design.widget.AppBarLayout.Behavior


默认AppBarLayout.BehaviorAppBarLayout 通过偏移实现必要的嵌套滚动处理。

Summary

Nested classes

class AppBarLayout.Behavior.DragCallback

回调以允许控制任何AppBarLayout拖动。

class AppBarLayout.Behavior.SavedState

 

Public constructors

AppBarLayout.Behavior()
AppBarLayout.Behavior(Context context, AttributeSet attrs)

Public methods

int getLeftAndRightOffset()
int getTopAndBottomOffset()
boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev)

在分派给子视图之前,响应CoordinatorLayout触摸事件。

boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection)

当父母CoordinatorLayout关于布置给定子视图时调用。

boolean onLayoutChild(CoordinatorLayout parent, AppBarLayout abl, int layoutDirection)

当父母CoordinatorLayout关于布置给定子视图时调用。

boolean onMeasureChild(CoordinatorLayout parent, AppBarLayout child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed)

父母CoordinatorLayout即将测量给定子视图时调用。

boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, float velocityX, float velocityY, boolean consumed)

当嵌套滚动的小孩正在开始一个投射或一个将是一个投掷的动作时调用。

void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, int dx, int dy, int[] consumed)

在目标已消耗任何滚动距离之前,正在进行嵌套滚动更新时调用。

void onNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed)

当正在进行嵌套滚动更新并且目标已滚动或尝试滚动时调用。

void onRestoreInstanceState(CoordinatorLayout parent, AppBarLayout appBarLayout, Parcelable state)

挂钩允许行为重新应用其以前由 onSaveInstanceState(CoordinatorLayout, V)生成的内部状态的表示。

Parcelable onSaveInstanceState(CoordinatorLayout parent, AppBarLayout appBarLayout)

Hook允许一个行为生成一个内部状态的表示,以后可以用它来创建一个具有相同状态的新实例。

boolean onStartNestedScroll(CoordinatorLayout parent, AppBarLayout child, View directTargetChild, View target, int nestedScrollAxes)

当CoordinatorLayout的后代尝试启动嵌套滚动时调用。

void onStopNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout abl, View target)

当嵌套滚动结束时调用。

boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev)

在行为开始 intercepting之后,对CoordinatorLayout触摸事件 intercepting

void setDragCallback(AppBarLayout.Behavior.DragCallback callback)

设置回调以控制任何 AppBarLayout拖动。

boolean setLeftAndRightOffset(int offset)
boolean setTopAndBottomOffset(int offset)

Protected methods

void layoutChild(CoordinatorLayout parent, V child, int layoutDirection)

Inherited methods

From class android.support.design.widget.CoordinatorLayout.Behavior
From class java.lang.Object

Public constructors

AppBarLayout.Behavior

AppBarLayout.Behavior ()

AppBarLayout.Behavior

AppBarLayout.Behavior (Context context, 
                AttributeSet attrs)

Parameters
context Context
attrs AttributeSet

Public methods

getLeftAndRightOffset

int getLeftAndRightOffset ()

Returns
int

getTopAndBottomOffset

int getTopAndBottomOffset ()

Returns
int

onInterceptTouchEvent

boolean onInterceptTouchEvent (CoordinatorLayout parent, 
                V child, 
                MotionEvent ev)

在分派给子视图之前,响应CoordinatorLayout触摸事件。

行为可以使用它来监控入站触摸事件,直到决定拦截事件流的其余部分以对其关联的子视图执行操作为止。 此方法将返回false直到它检测到正确的拦截条件,然后在发生这些条件后返回true。

一旦行为截取触摸事件,事件流的其余部分将被发送到 onTouchEvent(CoordinatorLayout, V, MotionEvent)方法。

此方法的默认实现始终返回false。

Parameters
parent CoordinatorLayout: the parent view currently receiving this touch event
child V: the child view associated with this Behavior
ev MotionEvent: the MotionEvent describing the touch event being processed
Returns
boolean true if this Behavior would like to intercept and take over the event stream. The default always returns false.

onLayoutChild

boolean onLayoutChild (CoordinatorLayout parent, 
                V child, 
                int layoutDirection)

当父母CoordinatorLayout关于布置给定子视图时调用。

此方法可用于执行子视图的自定义或修改布局,以取代默认子布局行为。 行为的实现可以通过调用parent.onLayoutChild委托给标准CoordinatorLayout测量行为。

如果行为实现onDependentViewChanged(CoordinatorLayout, android.view.View, android.view.View)以响应相关视图更改而更改视图的位置,则还应该以尊重这些相关视图的方式实现onLayoutChild onLayoutChild依赖关系后,将始终调用onLayoutChild依赖视图。

Parameters
parent CoordinatorLayout: the parent CoordinatorLayout
child V: child view to lay out
layoutDirection int: the resolved layout direction for the CoordinatorLayout, such as LAYOUT_DIRECTION_LTR or LAYOUT_DIRECTION_RTL.
Returns
boolean true if the Behavior performed layout of the child view, false to request default layout behavior

onLayoutChild

boolean onLayoutChild (CoordinatorLayout parent, 
                AppBarLayout abl, 
                int layoutDirection)

当父母CoordinatorLayout关于布置给定子视图时调用。

此方法可用于执行子视图的自定义或修改布局,以取代默认子布局行为。 行为的实现可以通过调用parent.onLayoutChild委托给标准的CoordinatorLayout测量行为。

如果行为实现onDependentViewChanged(CoordinatorLayout, android.view.View, android.view.View)以响应相关视图更改而更改视图的位置,则还应该以尊重这些相关视图的方式实现onLayoutChild onLayoutChild 其依赖项已经布局后,将始终调用依赖视图。

Parameters
parent CoordinatorLayout: the parent CoordinatorLayout
abl AppBarLayout: child view to lay out
layoutDirection int: the resolved layout direction for the CoordinatorLayout, such as LAYOUT_DIRECTION_LTR or LAYOUT_DIRECTION_RTL.
Returns
boolean true if the Behavior performed layout of the child view, false to request default layout behavior

onMeasureChild

boolean onMeasureChild (CoordinatorLayout parent, 
                AppBarLayout child, 
                int parentWidthMeasureSpec, 
                int widthUsed, 
                int parentHeightMeasureSpec, 
                int heightUsed)

父母CoordinatorLayout即将测量给定子视图时调用。

此方法可用于执行自定义或修改的子视图测量,以代替默认的子测量行为。 行为的实现可以通过调用parent.onMeasureChild委托给标准CoordinatorLayout测量行为。

Parameters
parent CoordinatorLayout: the parent CoordinatorLayout
child AppBarLayout: the child to measure
parentWidthMeasureSpec int: the width requirements for this view
widthUsed int: extra space that has been used up by the parent horizontally (possibly by other children of the parent)
parentHeightMeasureSpec int: the height requirements for this view
heightUsed int: extra space that has been used up by the parent vertically (possibly by other children of the parent)
Returns
boolean true if the Behavior measured the child view, false if the CoordinatorLayout should perform its default measurement

onNestedFling

boolean onNestedFling (CoordinatorLayout coordinatorLayout, 
                AppBarLayout child, 
                View target, 
                float velocityX, 
                float velocityY, 
                boolean consumed)

当嵌套滚动的小孩正在开始一个投射或一个将是一个投掷的动作时调用。

任何与CoordinatorLayout的直接子项关联的行为都可以选择接受嵌套滚动,作为onStartNestedScroll(CoordinatorLayout, V, View, View, int)一部分。 每个返回true的行为都将接收该嵌套滚动的后续嵌套滚动事件。

onNestedFling当当前嵌套滚动子视图检测到适合条件的适当条件时调用。 它报告孩子本身是否消费了这一招。 如果没有,该小孩预计会出现某种过度滚动的指示。 如果这个方法消耗了这个方块,那么这个方法应该返回true,这样一个自己没有采取行动的孩子可以选择不显示超出指示。

Parameters
coordinatorLayout CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with
child AppBarLayout: the child view of the CoordinatorLayout this Behavior is associated with
target View: the descendant view of the CoordinatorLayout performing the nested scroll
velocityX float: horizontal velocity of the attempted fling
velocityY float: vertical velocity of the attempted fling
consumed boolean: true if the nested child view consumed the fling
Returns
boolean true if the Behavior consumed the fling

onNestedPreScroll

void onNestedPreScroll (CoordinatorLayout coordinatorLayout, 
                AppBarLayout child, 
                View target, 
                int dx, 
                int dy, 
                int[] consumed)

在目标已消耗任何滚动距离之前,正在进行嵌套滚动更新时调用。

与CoordinatorLayout的直接子项关联的任何行为都可以选择接受嵌套滚动,作为onStartNestedScroll(CoordinatorLayout, V, View, View, int)一部分。 每个返回true的行为都将接收该嵌套滚动的后续嵌套滚动事件。

onNestedPreScroll嵌套滚动更新时,嵌套滚动子组自动消耗滚动距离之前调用onNestedPreScroll 每个响应嵌套滚动的行为都会收到相同的值。 CoordinatorLayout将报告消耗的任何方向上的最大像素数,即任何响应嵌套滚动的行为都被报告为已消耗。

Parameters
coordinatorLayout CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with
child AppBarLayout: the child view of the CoordinatorLayout this Behavior is associated with
target View: the descendant view of the CoordinatorLayout performing the nested scroll
dx int: the raw horizontal number of pixels that the user attempted to scroll
dy int: the raw vertical number of pixels that the user attempted to scroll
consumed int: 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

onNestedScroll

void onNestedScroll (CoordinatorLayout coordinatorLayout, 
                AppBarLayout child, 
                View target, 
                int dxConsumed, 
                int dyConsumed, 
                int dxUnconsumed, 
                int dyUnconsumed)

当正在进行嵌套滚动更新并且目标已滚动或尝试滚动时调用。

任何与CoordinatorLayout的直接子项关联的行为都可能选择接受嵌套滚动,作为onStartNestedScroll(CoordinatorLayout, V, View, View, int)一部分。 每个返回true的行为都将接收该嵌套滚动的后续嵌套滚动事件。

onNestedScroll嵌套滚动更新时,调用onNestedScroll滚动消耗和未消耗的滚动组件都以像素为单位提供。 每个响应嵌套滚动的行为都会收到相同的值。

Parameters
coordinatorLayout CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with
child AppBarLayout: the child view of the CoordinatorLayout this Behavior is associated with
target View: the descendant view of the CoordinatorLayout performing the nested scroll
dxConsumed int: horizontal pixels consumed by the target's own scrolling operation
dyConsumed int: vertical pixels consumed by the target's own scrolling operation
dxUnconsumed int: horizontal pixels not consumed by the target's own scrolling operation, but requested by the user
dyUnconsumed int: vertical pixels not consumed by the target's own scrolling operation, but requested by the user

onRestoreInstanceState

void onRestoreInstanceState (CoordinatorLayout parent, 
                AppBarLayout appBarLayout, 
                Parcelable state)

挂钩允许行为重新应用其以前由onSaveInstanceState(CoordinatorLayout, V)生成的内部状态的表示。 这个函数永远不会被调用为null状态。

Parameters
parent CoordinatorLayout: the parent CoordinatorLayout
appBarLayout AppBarLayout: child view to restore from
state Parcelable: The frozen state that had previously been returned by onSaveInstanceState(CoordinatorLayout, V).

onSaveInstanceState

Parcelable onSaveInstanceState (CoordinatorLayout parent, 
                AppBarLayout appBarLayout)

Hook允许一个行为生成一个内部状态的表示,以后可以用它来创建一个具有相同状态的新实例。 此状态应仅包含不持久或以后不能重建的信息。

行为状态仅在父级 CoordinatorLayout和使用此行为的视图设置有效ID时才被保存。

Parameters
parent CoordinatorLayout: the parent CoordinatorLayout
appBarLayout AppBarLayout: child view to restore from
Returns
Parcelable Returns a Parcelable object containing the behavior's current dynamic state.

onStartNestedScroll

boolean onStartNestedScroll (CoordinatorLayout parent, 
                AppBarLayout child, 
                View directTargetChild, 
                View target, 
                int nestedScrollAxes)

当CoordinatorLayout的后代尝试启动嵌套滚动时调用。

与CoordinatorLayout的任何直接子节点相关联的任何行为都可能会响应此事件,并返回true以指示CoordinatorLayout应作为此滚动的嵌套滚动父级。 只有从此方法返回true的行为才会接收后续的嵌套滚动事件。

Parameters
parent CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with
child AppBarLayout: the child view of the CoordinatorLayout this Behavior is associated with
directTargetChild View: the child view of the CoordinatorLayout that either is or contains the target of the nested scroll operation
target View: the descendant view of the CoordinatorLayout initiating the nested scroll
nestedScrollAxes int: the axes that this nested scroll applies to. See SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_VERTICAL
Returns
boolean true if the Behavior wishes to accept this nested scroll

onStopNestedScroll

void onStopNestedScroll (CoordinatorLayout coordinatorLayout, 
                AppBarLayout abl, 
                View target)

当嵌套滚动结束时调用。

与CoordinatorLayout的任何直接子项关联的任何行为都可以选择接受嵌套滚动,作为onStartNestedScroll(CoordinatorLayout, V, View, View, int)一部分。 每个返回true的行为都将接收该嵌套滚动的后续嵌套滚动事件。

onStopNestedScroll表示单个嵌套滚动事件序列的结束。 这是清理与嵌套滚动相关的任何状态的好地方。

Parameters
coordinatorLayout CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with
abl AppBarLayout: the child view of the CoordinatorLayout this Behavior is associated with
target View: the descendant view of the CoordinatorLayout that initiated the nested scroll

onTouchEvent

boolean onTouchEvent (CoordinatorLayout parent, 
                V child, 
                MotionEvent ev)

在此行为已启动之后,响应CoordinatorLayout触摸事件 intercepting

行为可以拦截触摸事件以帮助CoordinatorLayout操纵其子视图。 例如,行为可能允许用户拖动打开或关闭的UI窗格。 该方法应该执行视图布局状态的实际突变。

Parameters
parent CoordinatorLayout: the parent view currently receiving this touch event
child V: the child view associated with this Behavior
ev MotionEvent: the MotionEvent describing the touch event being processed
Returns
boolean true if this Behavior handled this touch event and would like to continue receiving events in this stream. The default always returns false.

setDragCallback

void setDragCallback (AppBarLayout.Behavior.DragCallback callback)

设置一个回调来控制任何 AppBarLayout拖动。

Parameters
callback AppBarLayout.Behavior.DragCallback: the callback to use, or null to use the default behavior.

setLeftAndRightOffset

boolean setLeftAndRightOffset (int offset)

Parameters
offset int
Returns
boolean

setTopAndBottomOffset

boolean setTopAndBottomOffset (int offset)

Parameters
offset int
Returns
boolean

Protected methods

layoutChild

void layoutChild (CoordinatorLayout parent, 
                V child, 
                int layoutDirection)

Parameters
parent CoordinatorLayout
child V
layoutDirection int

Hooray!