android-autofittextview icon indicating copy to clipboard operation
android-autofittextview copied to clipboard

Text in one line only

Open pawelantczak opened this issue 10 years ago • 6 comments

Hello. What I want to achieve is exactly what is shown on animation. But, if I set android:singleLine="true" text never expands to second line. If single line is not set, resizing don't work.

Even if I run your demo, text is always in one line. How to make it behave as on animated gif?

pawelantczak avatar Jan 18 '15 12:01 pawelantczak

Use android:maxLines="2" instead of android:singleLine="true".

grantland avatar Jan 21 '15 06:01 grantland

Using maxLines="2" doesn't work because in AutofitHelper.autofit() you call getAutofitTextSize only if maxLines==1. I deleted this requirement in my subclass and it works.

herrbert74 avatar Apr 28 '15 16:04 herrbert74

It should work though, because I check that OR lineCount > maxLines here: https://github.com/grantland/android-autofittextview/blob/master/library/src/main/java/me/grantland/widget/AutofitHelper.java#L125

Is that returning something incorrect?

grantland avatar Apr 28 '15 17:04 grantland

I see. For me the text was two words on a button, and the first word was too long, so it was chopped and the second part was added to the second line. The second line wasn't too long even so, so getAutofitTextSize was never triggered. So basically it doesn't work if a single word is longer than a line. We need a check for that.

herrbert74 avatar Apr 29 '15 10:04 herrbert74

  1. use the type class TextView instead of class AutofitTextView.
  2. add textView.setMaxLines(2) programmatically and AutofitHelper.create(textView)

sehoi avatar Dec 17 '15 08:12 sehoi

@sehoi this doesn't seem to work on my side. The behavior is the same as if I set it in xml

@herrbert74 is right - it seems to happen when a single word is longer than a line.

niosus avatar Jan 06 '16 16:01 niosus