Android 如何使用AppBarLayout.ScrollingViewBehavior';什么是数学?

Android 如何使用AppBarLayout.ScrollingViewBehavior';什么是数学?,android,android-coordinatorlayout,android-appbarlayout,Android,Android Coordinatorlayout,Android Appbarlayout,我将观察AppBarLayout.ScrollingViewBehavior中OffsetChildAsneed方法在运行滚动更改时的数学流程 由于它是私有方法,而私有是mOffsetDelta,如何以编程方式监视它们 (该方法如何使用偏移量也不清楚。) 注意:欢迎您的回复,也可以接受这些回复。这些回复解释了getTopBottomOffsetForScrollingSibling()、(dependency.getBottom()-child.getTop())、以及mOffsetDelta的

我将观察AppBarLayout.ScrollingViewBehavior中OffsetChildAsneed方法在运行滚动更改时的数学流程

由于它是私有方法,而私有是
mOffsetDelta
,如何以编程方式监视它们

(该方法如何使用偏移量也不清楚。)


注意:欢迎您的回复,也可以接受这些回复。这些回复解释了
getTopBottomOffsetForScrollingSibling()
(dependency.getBottom()-child.getTop())
、以及
mOffsetDelta

的数学逻辑细节,您可以对这些代码进行反向工程,但归根结底,这是学术性的,因为我们这些凡人(即非谷歌)程序员无法访问此处显示的值和方法。我猜他们认为我们实际使用的库越少,我们提交的bug报告就越少。唉

但这里有一个简单的解释:

首先是代码行

    final int offset = ablBehavior.getTopBottomOffsetForScrollingSibling();
似乎是早期版本的残余,因为
offset
从未实际使用过。在更多情况下,较新的表达式必须更精确一点

ViewCompat.offsetopandbottom()
不是一个集合(绝对)操作,而是一个加法(相对)操作。因此,让我们假设正常的逻辑,并认为这种行为本质上将滚动视图直接放在应用程序栏布局下面。通常,应用程序栏的底部和滚动视图的顶部具有相同的值。由于应用程序栏布局(依赖项)已更改,而滚动视图(子项)尚未更改,因此

子对象的垂直偏移需要调整的相对量

如果我对代码的读取是正确的,则应用程序条布局行为中的
mOffsetDelta
仅在应用程序条布局具有偏移插值器的情况下为非零。通常,应用程序栏本身不会以视差方式移动,因此对于我们关心的几乎所有情况,
mOffsetDelta
都为零
getVerticalLayoutGap
getOverlappixelsofset
处理布局参数,如
OverlappTop

但事实证明,通过这样做,您可以在自己的行为子类中不使用这些边缘情况来完成大部分工作:

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, View child,
                                          View dependency) {
        // get the bottom of the app bar layout
        int bottom = dependency.getBottom();

        // position the top of the scrolling view there
        return setTopAndBottomOffset(bottom);
    }

我发现使用绝对偏移比使用相对偏移更容易一些。因此,实现滚动行为主要是确定从属视图的位置以及滚动视图需要基于该位置的位置。

最好解释一下最终目标,而不是您计划实现它的方式。最终目标是在滚动查看
AppBarLayout时学习行为如何工作。滚动查看行为类到您的项目,进行更改,将您的
AppBarLayout
app:layou行为指向它,利润。我正在尝试这样做,但在AppBarLayout.Behavior中,父标题CrollingViewBehavior和mOffsetDelta的原始包不可见。我非常希望使用
AppBarLayout.ScrollingViewBehavior的子类中的
OffsetChildaNeed
的结果。这方面有更新吗?
    dependency.getBottom() - child.getTop()
    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, View child,
                                          View dependency) {
        // get the bottom of the app bar layout
        int bottom = dependency.getBottom();

        // position the top of the scrolling view there
        return setTopAndBottomOffset(bottom);
    }