使用自定义ScrollingViewBehavior的Viewpager底部填充跳过

时间:2018-06-30 16:51:09

标签: android

我有一个选项卡式活动和一个viewpager自定义ScrollingViewBehavior,用于滚动appbar。 滚动应用栏时,视图寻呼机的底部填充会跳过。 行为(根据另一篇文章的解决方案...)如下:

public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {

        if (appBarLayout == null) {
            appBarLayout = (AppBarLayout) dependency;
            maxTop = 72;
        }

        final boolean result = super.onDependentViewChanged(parent, child, dependency);
        int currenttop = dependency.getTop();

        if (currenttop > maxTop)   maxTop = currenttop;
        final int bottomPadding = calculateBottomPadding(appBarLayout);
        final boolean paddingChanged = bottomPadding != child.getPaddingBottom();
        if (paddingChanged) {
            child.setPadding(
                    child.getPaddingLeft(),
                    child.getPaddingTop(),
                    child.getPaddingRight(),
                    bottomPadding);
            child.requestLayout();
        }
        return paddingChanged || result;
    }


    // Calculate the padding needed to keep the bottom of the view pager's content at the same location on the screen.
    private int calculateBottomPadding(AppBarLayout dependency) {
        final int totalScrollRange = dependency.getTotalScrollRange();//getTotalScrollRange();
        final int deptop = dependency.getTop();
        return  deptop + totalScrollRange - maxTop;
    }
}

结果是(GIF): scroll behavior

为什么要下跳?!

还有一个侧面的问题:在onDependentViewChanged中,我发现了一个常量值(maxTop = 72)以进行正确的填充!为什么?!我不明白!

表示“ SOF”和用户。

0 个答案:

没有答案