diff options
| author | Siyamed Sinir <siyamed@google.com> | 2016-05-25 11:16:22 -0700 |
|---|---|---|
| committer | Siyamed Sinir <siyamed@google.com> | 2016-05-25 12:01:23 -0700 |
| commit | f75775ea7ff25fc9039ce7994312b29419294902 (patch) | |
| tree | 37dad2582c694d47a1f3bf261b582d3372d9f460 /core/java/android/widget/TextView.java | |
| parent | 0f6363e8b3b091508181ea6cef5f5f87a4f75016 (diff) | |
Fix TextView layout reuse when maxLines is set
When maxLines is set on StaticLayout and the text is wrapped, during
onMeasure TextView couldn’t recognize the wrap in the layout and tried
to reuse the layout which in turn caused width calculation problems.
This CL checks if maxLines is set, and if there is a text cut-off in
order to reuse existing layout.
Bug: 28468120
Change-Id: Ide43df8512a09112715067cbadf29cc64fd53247
Diffstat (limited to 'core/java/android/widget/TextView.java')
| -rw-r--r-- | core/java/android/widget/TextView.java | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index fc120eb0e65f..3711b9402f3a 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -6983,14 +6983,19 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return false; } - private static int desired(Layout layout) { + private static int desired(Layout layout, int maxLines) { int n = layout.getLineCount(); CharSequence text = layout.getText(); float max = 0; + // if maxLines is set, and the text length is greater that the length of the text in the + // layout, it means that there is a cut-off and we cannot use it. + if (maxLines != -1 && text.length() > layout.getLineEnd(n - 1)) { + return -1; + } + // if any line was wrapped, we can't use it. // but it's ok for the last line not to have a newline - for (int i = 0; i < n - 1; i++) { if (text.charAt(layout.getLineEnd(i) - 1) != '\n') return -1; @@ -7063,7 +7068,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener width = widthSize; } else { if (mLayout != null && mEllipsize == null) { - des = desired(mLayout); + des = desired(mLayout, getMaxLines()); } if (des < 0) { @@ -7095,7 +7100,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener int hintWidth; if (mHintLayout != null && mEllipsize == null) { - hintDes = desired(mHintLayout); + hintDes = desired(mHintLayout, getMaxLines()); } if (hintDes < 0) { |
