From 84d3d9ef92cf8313c4e3260f7ccbc28fadd27ac6 Mon Sep 17 00:00:00 2001 From: afohrman Date: Thu, 17 Aug 2017 16:43:14 -0400 Subject: [PATCH] Reposition label to adapt to box surroundings. Move the collapsed and expanded bounds of the floating label towards where each belongs. This commit is the first stage in setting the floating label's bounds, so it avoids calculating the exact dimensions based on internal dimensions. The label positioning work is being broken up into stages since the internal dimensions of the text field will likely change either in an upcoming design rethink and while adding the dimension parameters. The final dimensions will be set once the design is agreed upon, and probably during the dimension parameterization phase. PiperOrigin-RevId: 165622891 --- .../design/widget/TextInputLayout.java | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/src/android/support/design/widget/TextInputLayout.java b/lib/src/android/support/design/widget/TextInputLayout.java index c67995ee7..c473bb9fd 100644 --- a/lib/src/android/support/design/widget/TextInputLayout.java +++ b/lib/src/android/support/design/widget/TextInputLayout.java @@ -1328,27 +1328,26 @@ public class TextInputLayout extends LinearLayout { if (mTextInputBoxBackground != null) { updateTextInputBoxBounds(); } - - if (mHintEnabled && mEditText != null) { - final Rect rect = mTmpRect; - ViewGroupUtils.getDescendantRect(this, mEditText, rect); - - final int l = rect.left + mEditText.getCompoundPaddingLeft(); - final int r = rect.right - mEditText.getCompoundPaddingRight(); - - mCollapsingTextHelper.setExpandedBounds( - l, - rect.top + mEditText.getCompoundPaddingTop(), - r, - rect.bottom - mEditText.getCompoundPaddingBottom()); - - // Set the collapsed bounds to be the full height (minus padding) to match the - // EditText's editable area - mCollapsingTextHelper.setCollapsedBounds( - l, getPaddingTop(), r, bottom - top - getPaddingBottom()); - - mCollapsingTextHelper.recalculate(); + if (!mHintEnabled || mEditText == null) { + return; } + + final Rect rect = mTmpRect; + ViewGroupUtils.getDescendantRect(this, mEditText, rect); + + final int l = rect.left + mEditText.getCompoundPaddingLeft(); + final int r = rect.right - mEditText.getCompoundPaddingRight(); + + final int collapsedTop = mEditText.getPaddingTop() / 2; + final int collapsedBottom = bottom - top - getPaddingBottom(); + + final int expandedTop = rect.top; + final int expandedBottom = rect.bottom - mEditText.getCompoundPaddingBottom(); + + mCollapsingTextHelper.setExpandedBounds(l, expandedTop, r, expandedBottom); + mCollapsingTextHelper.setCollapsedBounds(l, collapsedTop, r, collapsedBottom); + + mCollapsingTextHelper.recalculate(); } private void collapseHint(boolean animate) {