Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – Cheesesquare:enterAlways产生错误的布局大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

将enterAlways添加到Cheesesquare演示的滚动标志:

导致错误的布局:

android  –  Cheesesquare:enterAlways产生错误的布局

在向下滚动期间,标题正确进入,但它不会停在正确的位置.滚动进一步取代零件:背景图像显示错误的位置,工具栏因背景颜色的变化而变得不可见. (我还在这里为工具栏添加一个colorPriMary背景,使其更加明显,但问题当然不依赖于颜色).这些库是截至今天的最新版本,23.1.0.

是否有任何解决方法或我们必须等待它在库中修复?现在,它似乎是任何需要此功能的应用程序的showstopper.

enterAlwaysCollapsed工作,但它提供了不同的功能,它不是一种解决方法.

最佳答案
我通过对AppBarLayout类源代码进行了一些修补来解决了这个问题.显然他们并不认为人们会这样使用它.或者他们做了,我离开了.无论如何它对我有用.

您需要对此方法进行一些小改动.寻找SCROLL_FLAG_EXIT_UNTIL_COLLAPSED

 /**
 * Return the scroll range when scrolling down from a nested pre-scroll.
 */
privatE int getDownnestedPreScrollRange() {
    if (mDownPreScrollRange != INVALID_SCROLL_RANGE) {
        // If we already have a valid value,return it
        return mDownPreScrollRange;
    }

    int range = 0;
    for (int i = getChildCount() - 1; i >= 0; i--) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        final int childHeight = child.getMeasuredHeight();
        final int flags = lp.mScrollFlags;

        if ((flags & LayoutParams.FLAG_QUICK_RETURN) == LayoutParams.FLAG_QUICK_RETURN) {
            // First take the margin into account
            range += lp.topMargin + lp.bottomMargin;
            // The view has the quick return flag combination...
            if ((flags & LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED) != 0) {
                // If they're set to enter collapsed,use the minimum height
                range += ViewCompat.getMinimumHeight(child);
                // This is what is missing...
            } else if ((flags & LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED) == LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED) {
                range += childHeight - ViewCompat.getMinimumHeight(child);
            } else {
                // Else use the full height
                range += childHeight;
            }
        } else if (range > 0) {
            // If we've hit an non-quick return scrollable view,and we've already hit a
            // quick return view,return Now
            break;
        }
    }
    return mDownPreScrollRange = range;
}

如果使用,可能需要递减状态栏高度
 “机器人:fitsSystemWindows =” 真”.

希望能帮助到你.您需要从设计库中复制一些类以允许所有导入和输入.一些将公开的方法.

干杯.

大佬总结

以上是大佬教程为你收集整理的android – Cheesesquare:enterAlways产生错误的布局全部内容,希望文章能够帮你解决android – Cheesesquare:enterAlways产生错误的布局所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。