From b5ab60dc9aed00de7e2d690606583f6710040b68 Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Wed, 30 Nov 2016 01:33:47 +0000 Subject: [PATCH] am c25d71b7: am 756b701d: Merge "Fix CollapsingToolbarLayout when used with SearchView" into mnc-ub-dev * commit 'c25d71b7961bb54676a9989b77d9ac4834d5698c': Fix CollapsingToolbarLayout when used with SearchView GitOrigin-RevId=f6cb6956bc3f8af302d222a6534c906f7c67efde PiperOrigin-RevId: 140550256 --- .../widget/CollapsingToolbarLayout.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/android/support/design/widget/CollapsingToolbarLayout.java b/src/android/support/design/widget/CollapsingToolbarLayout.java index 184403438..d20c42050 100644 --- a/src/android/support/design/widget/CollapsingToolbarLayout.java +++ b/src/android/support/design/widget/CollapsingToolbarLayout.java @@ -104,6 +104,7 @@ public class CollapsingToolbarLayout extends FrameLayout { private final Rect mTmpRect = new Rect(); private final CollapsingTextHelper mCollapsingTextHelper; private boolean mCollapsingTitleEnabled; + private boolean mDrawCollapsingTitle; private Drawable mContentScrim; private Drawable mStatusBarScrim; @@ -258,7 +259,7 @@ public class CollapsingToolbarLayout extends FrameLayout { } // Let the collapsing text helper draw it's text - if (mCollapsingTitleEnabled) { + if (mCollapsingTitleEnabled && mDrawCollapsingTitle) { mCollapsingTextHelper.draw(canvas); } @@ -367,17 +368,23 @@ public class CollapsingToolbarLayout extends FrameLayout { // Update the collapsed bounds by getting it's transformed bounds. This needs to be done // before the children are offset below if (mCollapsingTitleEnabled && mDummyView != null) { - ViewGroupUtils.getDescendantRect(this, mDummyView, mTmpRect); - mCollapsingTextHelper.setCollapsedBounds(mTmpRect.left, bottom - mTmpRect.height(), - mTmpRect.right, bottom); - // Update the expanded bounds - mCollapsingTextHelper.setExpandedBounds( - mExpandedMarginLeft, - mTmpRect.bottom + mExpandedMarginTop, - right - left - mExpandedMarginRight, - bottom - top - mExpandedMarginBottom); + // We only draw the title if the dummy view is being displayed (Toolbar removes + // views if there is no space) + mDrawCollapsingTitle = mDummyView.isShown(); - mCollapsingTextHelper.recalculate(); + if (mDrawCollapsingTitle) { + ViewGroupUtils.getDescendantRect(this, mDummyView, mTmpRect); + mCollapsingTextHelper.setCollapsedBounds(mTmpRect.left, bottom - mTmpRect.height(), + mTmpRect.right, bottom); + // Update the expanded bounds + mCollapsingTextHelper.setExpandedBounds( + mExpandedMarginLeft, + mTmpRect.bottom + mExpandedMarginTop, + right - left - mExpandedMarginRight, + bottom - top - mExpandedMarginBottom); + // Now recalculate using the new bounds + mCollapsingTextHelper.recalculate(); + } } // Update our child view offset helpers