diff --git a/src/android/support/design/widget/AppBarLayout.java b/src/android/support/design/widget/AppBarLayout.java index 17216c62c..aa76a6b02 100644 --- a/src/android/support/design/widget/AppBarLayout.java +++ b/src/android/support/design/widget/AppBarLayout.java @@ -1283,20 +1283,20 @@ public class AppBarLayout extends LinearLayout { } @Override - public Parcelable onSaveInstanceState(CoordinatorLayout parent, AppBarLayout appBarLayout) { - final Parcelable superState = super.onSaveInstanceState(parent, appBarLayout); + public Parcelable onSaveInstanceState(CoordinatorLayout parent, AppBarLayout abl) { + final Parcelable superState = super.onSaveInstanceState(parent, abl); final int offset = getTopAndBottomOffset(); // Try and find the first visible child... - for (int i = 0, count = appBarLayout.getChildCount(); i < count; i++) { - View child = appBarLayout.getChildAt(i); + for (int i = 0, count = abl.getChildCount(); i < count; i++) { + View child = abl.getChildAt(i); final int visBottom = child.getBottom() + offset; if (child.getTop() + offset <= 0 && visBottom >= 0) { final SavedState ss = new SavedState(superState); ss.firstVisibleChildIndex = i; ss.firstVisibleChildAtMinimumHeight = - visBottom == ViewCompat.getMinimumHeight(child); + visBottom == (ViewCompat.getMinimumHeight(child) + abl.getTopInset()); ss.firstVisibleChildPercentageShown = visBottom / (float) child.getHeight(); return ss; } diff --git a/src/android/support/design/widget/CollapsingToolbarLayout.java b/src/android/support/design/widget/CollapsingToolbarLayout.java index 1d90a3f75..39ad03b20 100644 --- a/src/android/support/design/widget/CollapsingToolbarLayout.java +++ b/src/android/support/design/widget/CollapsingToolbarLayout.java @@ -413,20 +413,19 @@ public class CollapsingToolbarLayout extends FrameLayout { protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); - // Update our child view offset helpers - for (int i = 0, z = getChildCount(); i < z; i++) { - final View child = getChildAt(i); - - if (mLastInsets != null && !ViewCompat.getFitsSystemWindows(child)) { - final int insetTop = mLastInsets.getSystemWindowInsetTop(); - if (child.getTop() < insetTop) { - // If the child isn't set to fit system windows but is drawing within the inset - // offset it down - ViewCompat.offsetTopAndBottom(child, insetTop); + if (mLastInsets != null) { + // Shift down any views which are not set to fit system windows + final int insetTop = mLastInsets.getSystemWindowInsetTop(); + for (int i = 0, z = getChildCount(); i < z; i++) { + final View child = getChildAt(i); + if (!ViewCompat.getFitsSystemWindows(child)) { + if (child.getTop() < insetTop) { + // If the child isn't set to fit system windows but is drawing within + // the inset offset it down + ViewCompat.offsetTopAndBottom(child, insetTop); + } } } - - getViewOffsetHelper(child).onViewLayout(); } // Update the collapsed bounds by getting it's transformed bounds @@ -465,6 +464,12 @@ public class CollapsingToolbarLayout extends FrameLayout { } } + // Update our child view offset helpers. This needs to be done after the title has been + // setup, so that any Toolbars are in their original position + for (int i = 0, z = getChildCount(); i < z; i++) { + getViewOffsetHelper(getChildAt(i)).onViewLayout(); + } + // Finally, set our minimum height to enable proper AppBarLayout collapsing if (mToolbar != null) { if (mCollapsingTitleEnabled && TextUtils.isEmpty(mCollapsingTextHelper.getText())) {