From 4c9765a654f7db15091d373f989908da54bfd155 Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Thu, 28 Aug 2014 19:21:18 -0700 Subject: [PATCH] Don't add title margins during to Toolbar layout if titles don't fit When all space is consumed in a Toolbar by other views the special shared title/subtitle margins shouldn't be added to the running position during layout. Bug 17253638 Change-Id: I179fcbf286fa68fd8df6e25bb1879bccbf1532ed --- core/java/android/widget/Toolbar.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/java/android/widget/Toolbar.java b/core/java/android/widget/Toolbar.java index 30ea7fbf2f11..f211b32b0f1f 100644 --- a/core/java/android/widget/Toolbar.java +++ b/core/java/android/widget/Toolbar.java @@ -1326,6 +1326,8 @@ public class Toolbar extends ViewGroup { final View bottomChild = layoutSubtitle ? mSubtitleTextView : mTitleTextView; final LayoutParams toplp = (LayoutParams) topChild.getLayoutParams(); final LayoutParams bottomlp = (LayoutParams) bottomChild.getLayoutParams(); + final boolean titleHasWidth = layoutTitle && mTitleTextView.getMeasuredWidth() > 0 + || layoutSubtitle && mSubtitleTextView.getMeasuredWidth() > 0; switch (mGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.TOP: @@ -1353,7 +1355,7 @@ public class Toolbar extends ViewGroup { break; } if (isRtl) { - final int rd = mTitleMarginStart - collapsingMargins[1]; + final int rd = (titleHasWidth ? mTitleMarginStart : 0) - collapsingMargins[1]; right -= Math.max(0, rd); collapsingMargins[1] = Math.max(0, -rd); int titleRight = right; @@ -1376,9 +1378,11 @@ public class Toolbar extends ViewGroup { subtitleRight = subtitleRight - mTitleMarginEnd; titleTop = subtitleBottom + lp.bottomMargin; } - right = Math.min(titleRight, subtitleRight); + if (titleHasWidth) { + right = Math.min(titleRight, subtitleRight); + } } else { - final int ld = mTitleMarginStart - collapsingMargins[0]; + final int ld = (titleHasWidth ? mTitleMarginStart : 0) - collapsingMargins[0]; left += Math.max(0, ld); collapsingMargins[0] = Math.max(0, -ld); int titleLeft = left; @@ -1401,7 +1405,9 @@ public class Toolbar extends ViewGroup { subtitleLeft = subtitleRight + mTitleMarginEnd; titleTop = subtitleBottom + lp.bottomMargin; } - left = Math.max(titleLeft, subtitleLeft); + if (titleHasWidth) { + left = Math.max(titleLeft, subtitleLeft); + } } } -- 2.11.0