【发布时间】:2017-02-22 14:59:33
【问题描述】:
我会在运行滚动更改时观察 AppBarLayout.ScrollingViewBehavior 中 offsetChildAsNeeded 方法的数学流程。
由于它是私有方法,私有是mOffsetDelta,如何以编程方式监控它们?
(也不清楚该方法如何使用offset。)
private void offsetChildAsNeeded(CoordinatorLayout parent, View child, View dependency) {
final CoordinatorLayout.Behavior behavior =
((CoordinatorLayout.LayoutParams) dependency.getLayoutParams()).getBehavior();
if (behavior instanceof Behavior) {
// Offset the child, pinning it to the bottom the header-dependency, maintaining
// any vertical gap, and overlap
final Behavior ablBehavior = (Behavior) behavior;
final int offset = ablBehavior.getTopBottomOffsetForScrollingSibling();
ViewCompat.offsetTopAndBottom(child, (dependency.getBottom() - child.getTop())
+ ablBehavior.mOffsetDelta
+ getVerticalLayoutGap()
- getOverlapPixelsForOffset(dependency));
}
}
注意:欢迎回复,也可以接受那些解释getTopBottomOffsetForScrollingSibling()、(dependency.getBottom() - child.getTop()) 的数学逻辑以及mOffsetDelta 内容的回复
【问题讨论】:
-
最好解释一下你的最终目标,而不是你计划实现它的方式。
-
最终目标是了解滚动更改时行为的工作原理
-
将
AppBarLayout.ScrollingViewBehavior类复制到您的项目中,进行更改,将您的AppBarLayout的app:layout_behavior指向它,获利。 -
我正在尝试,但是对于父 HeaderScrollingViewBehavior 和 AppBarLayout.Behavior 中的 mOffsetDelta,原始包中没有可见性。
-
我非常想在
AppBarLayout.ScrollingViewBehavior的子类中使用offsetChildAsNeeded的结果。有这方面的更新吗?
标签: android android-coordinatorlayout android-appbarlayout