Cheesesquare:enterAlways产生错误的布局 [英] Cheesesquare: enterAlways produces wrong layout

本文介绍了Cheesesquare:enterAlways产生错误的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Adding enterAlways to the scroll flags of the Cheesesquare demo:

<android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsing_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:contentScrim="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlways">

结果在错误的布局:

results in a wrong layout:

在这里输入的形象描述

在向下滚动,标题来正确地但它不会在正确的位置停止。进一步滚动置换部分:背景图像出现在错误的位置和工具栏变得因为在背景颜色的变化可见。 (我还添加了 colorPrimary 背景这里的工具栏,使之更加可见,但这个问题不取决于颜色,当然)。该库是最新的今天,23.1.0的。

During scrolling down, the header comes in correctly but it doesn't stop in the correct position. Scrolling further displaces the parts: the backdrop image appears in the wrong position and the toolbar becomes invisible because of the changes in the background color. (I also added a colorPrimary background to the toolbar here to make it more visible but the problem doesn't depend on the color, of course). The libraries are the latest as of today, 23.1.0.

有任何解决方法,否则我们必须等待它被固定在图书馆?现在,它似乎是任何应用程序需要此功能的搅局者。

Is there any workaround or we have to wait for it to be fixed in the library? Right now, it seems to be a showstopper for any app needing this functionality.

enterAlwaysCollapsed 工作,但给人的不同的功能,它不是一个解决办法。

enterAlwaysCollapsed works but that gives a different functionality, it's not a workaround.

推荐答案

我解决了一个位修补到AppBarLayout类源$ C ​​$ C的这个问题。显然,他们没有想到人们会这样使用它。或者,他们没有和我的路要走。反正它为我工作。

I solved this issue with a bit of patching to the AppBarLayout class source code. Apparently they didn't think people will use it like this. Or they did and I'm way off. anyways it works for me.

您需要做一个小的变化,以这种方法。寻找SCROLL_FLAG_EXIT_UNTIL_COLLAPSED

You need to make a small change to this method. look for 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 =真正的

You may need to decrement the status bar height if you are using "android:fitsSystemWindows="true".

希望它帮助。有一些类,您将需要从设计库复制到让所有的进口和放大器;一些方法,会变成公开。

Hope it helps. There a some classes that you will need to copy from the design library to allow all imports & some methods that will turn public.

干杯。

这篇关于Cheesesquare:enterAlways产生错误的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆