Skip to content Skip to sidebar Skip to footer

Cheesesquare: Enteralways Produces Wrong Layout

Adding enterAlways to the scroll flags of the Cheesesquare demo:

Solution 1:

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.

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 itreturn mDownPreScrollRange;
    }

    intrange = 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 accountrange += 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 heightrange += ViewCompat.getMinimumHeight(child);
                // This is what is missing...
            } elseif ((flags & LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED) == LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED) {
                range += childHeight - ViewCompat.getMinimumHeight(child);
            } else {
                // Else use the full heightrange += childHeight;
            }
        } elseif (range > 0) {
            // If we've hit an non-quick return scrollable view, and we've already hit a// quick return view, return nowbreak;
        }
    }
    return mDownPreScrollRange = range;
}

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.

Cheers.

Post a Comment for "Cheesesquare: Enteralways Produces Wrong Layout"