I have a TextView and I set text which I receive from Backend.
the text is either from 1 to 3 words.
Maximum the textview can be 2 lines.
I am using setAutoSizeTextTypeUniformWithConfiguration
and text.breakStrategy = LineBreaker.BREAK_STRATEGY_SIMPLE
And I don't have any success.
wondering is it possible if the text is single word I don't want to split it. I would like to have it in single line with small textSize. if the text is 2 words and long I am fine to show it in 2 lines. The problem is it always breaks the word in 2 lines if it is long while I don't want.
Asked
Active
Viewed 266 times
1

I.S
- 1,904
- 2
- 25
- 48
-
2If @Rinat's answer is not enough(since you also mention a smaller textSize), maybe you'll want to use a custom [Auto-fit TextView for Android](https://stackoverflow.com/q/16017165). Otherwise, Android doesn't offer a standard resizeable TextView. – Adinia Jan 12 '21 at 10:25
2 Answers
1
The only solution that comes to my mind is before setting the text to a textview, check whether text has spaces in it. If it has not that that means it's a single word, so set ptogrammatically maxlines to 1, otherwise set maxlines to 2.
EDIT: I missed text size part. I use this library for autoresizing and it worked so far https://github.com/jivimberg/AutoResizeTextView

Rinat Diushenov
- 1,215
- 7
- 15
0
it's automatically handled in androidx.appcompat.widget.AppCompatEditText
and just set android:maxLines="2"
remove all other properties you set

Shahriyar Aghajani
- 431
- 1
- 6
- 22