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
This commit is contained in:
afohrman 2017-08-17 16:43:14 -04:00 committed by Miguel Yanez Barreto
parent a0550d04c5
commit 84d3d9ef92

View File

@ -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) {