3

On my last activity i get a textView and if is too big it just stays the same size and goes to the next line. Is there any way to have my textView shrink so it can fit on one line if it is too big ?

So instead of :

ABCDEFGHIJ (big font on two lines)
HIJK

I want:

abcdefghijk (smaller font on one line )

So it all fits from left to right on one line within the fone

4

5 Answers 5

3

If you want to have autoresize on a TextView use this :

<TextView
        android:layout_width="60dp"
        android:layout_height="48dp" 
        android:lines="2"
        android:text="Hello world"
        android:autoSizeTextType="uniform"/>

What is very important is to not use android:singleLine="true" cos it's deprecated. Ans to have a fixed size so the autoresizing of the text will work correctly. You can also chose the number of line that you what.

Also note that with this the minimum size is 12sp, the maximum size is 112sp and the granularity is 1px. But if you want to custom those size, you can use :

android:autoSizeMinTextSize="8sp"
android:autoSizeMaxTextSize="100sp"
android:autoSizeStepGranularity="2sp"

That you can add to the above xml.

1

android:singleLine="true" this property in text view will help,it will not decrease the size of text but allow to show text in single line.

1
  • that just adds ... to the end of it Apr 21, 2012 at 17:51
1

This is a job for a custom View subclass. It’s very easy to create a View subclass, in this case you just need to override the onDraw method, since you don’t need to implement any special user interaction. Basically measure the width of the text at a reference point size, then choose a scaled point size based on that at which to draw the text.

1

1) Put android:lines="1" in your textview
2) If you want 3dots at end of lines then put android:ellipsize="end" in your textview

Note:
Do not use android:singleLine="true" as it is deprecated now.

0

Declare android:autoSizeMinTextSize or app:android:autoSizeMinTextSize (in supoort library) with 1sp to reduce the minimum texsize. If the line is not too long (I assume is your case) you'll have a solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.