Cheesesquare: enterAlways misplaced

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"> 

leads to the wrong location:

enter image description here

When scrolling down, the title does the right thing, but it does not stop in the right position. Scrolling additionally moves the details: the background image is displayed in the wrong position, and the toolbar becomes invisible due to changes in the background color. (I also added a colorPrimary background to the toolbar here to make it more visible, but the problem, of course, does not depend on color). Today, libraries are the latest, 23.1.0.

Is there any workaround, or should we wait for it to be fixed in the library? Right now, this seems to be a showstopper for any application that needs this functionality.

enterAlwaysCollapsed works, but it gives other functionality, this is not a workaround.

+5
source share
1 answer

I solved this problem with a small fix to the source code of the AppBarLayout class. Apparently, they did not think that people would use it that way. Or they did, and I left. anyway, it works for me.

You need to make a small change to this method. find 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; } 

You may need to reduce the height of the status bar if you are using. "Android: fitsSystemWindows =" true "

Hope this helps. There are several classes that you will need to copy from the design library to allow import and some methods that will become publicly available.

Greetings.

+2
source

All Articles