AutoSize TextView - take horizontalScrolling into account

When passing the characteristics of the current TextView
to the StaticLayout for auto-size measurements also take
the horizontallyScrolling into account similarly with how
the actual measurements are done (@ TextView#onMeasure).

Bug: 37254477
Test: cts-tradefed run cts-dev -m CtsWidgetTestCases -t\
      android.widget.cts.TextViewTest

Change-Id: I44b85e77d9b1770f188a0f59f103e3fda284e97a
This commit is contained in:
Andrei Stingaceanu
2017-04-12 15:57:38 +01:00
parent cf7cb9c993
commit f730651a22

View File

@@ -8196,9 +8196,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
mTempTextPaint.set(getPaint());
mTempTextPaint.setTextSize(suggestedSizeInPx);
final int availableWidth = mHorizontallyScrolling
? VERY_WIDE
: getMeasuredWidth() - getTotalPaddingLeft() - getTotalPaddingRight();
final StaticLayout.Builder layoutBuilder = StaticLayout.Builder.obtain(
text, 0, text.length(), mTempTextPaint,
getMeasuredWidth() - getTotalPaddingLeft() - getTotalPaddingRight());
text, 0, text.length(), mTempTextPaint, availableWidth);
layoutBuilder.setAlignment(getLayoutAlignment())
.setLineSpacing(getLineSpacingExtra(), getLineSpacingMultiplier())