首页 > 解决方案 > 使用自定义 ScrollingViewBehavior 跳过 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): 滚动行为

为什么要跳过底部?!

对于横向问题:在 onDependentViewChanged 中,我找到了一个用于正确填充的常量值(maxTop=72)!为什么?!我无法理解!

“SOF”和用户的坦克。

标签: android

解决方案


推荐阅读