Development issue/problem:

I am using the new autodetection feature that has been added to support library 26. I have read the documentation, which can be found here:
https://developer.android.com/preview/features/autosizing-textview.html.

I think that’s the way it has to be: You can enable automatic scaling with the attribute: app:autoSizeTextType=uniform. I think TextView should use all available space to display all text (not just part of it – it shouldn’t be truncated), and textSize should be as large as possible. If you want to limit the maximum or minimum text size, you can use these two attributes:

app:autoSizeMinTextSize=XXsp // (you can also use px or dp values).

or

app: autoSizeMaxTextSize=XXsp

So far, so good. Let’s say I need a 56dp wide TextView. I have texts of different lengths and I want to put them on this TextView. The size must be adjusted automatically so that the full text (all characters + uncoupled) is displayed in the maximum possible text size.

That’s my TextView:

Unfortunately, the text display has been cut off. I wanted to put this string as text in the TextView above: Group, but it’s a result:

(The TextView is located within a ConstraintLayout with a yellow circle as background).

As you can see, the text display is not adjusted at all. Do you have any idea what to do?

Thank you so much!

How can I solve this problem?

Solution 1:

I have tested it in different situations and came to the following conclusion:

They must be limited in width and height. If you z. B. Set width as match_older but wrap_content as height, I don’t think Android knows how high you want to stretch the text. In your example you don’t have a specific size, so I don’t think it will work.

For example:

Autosizing of TextView doesn’t work (Android O) –

Autosizing of TextView doesn’t work (Android O) –

I don’t know why the official Android document wrap_content as an example…. used as an example.

And as you can see, I didn’t use any other attributes in my example, so it’s probably not the bad attributes that are the problem.

And, yes, the TextView I use is android.support.v7.widget.AppCompatTextView.

And as long as you use the 26.0.0 or higher support library – that’s enough.

EDIT:

As with ConstraintLayout, the director is the same.
They must be limited in width and height, i.e. one or the other of the smaller dimensions for each size:

  1. You have specified an absolute value for this dimension (width or height).
  2. They impose a two-way restriction.

For example:

Autosizing of TextView doesn’t work (Android O) –
Autosizing of TextView doesn’t work (Android O) –
Autosizing of TextView doesn’t work (Android O) –

UPDATE: (2017-09-21)

I have checked, unfortunately it does not yet seem to support custom fonts, a feature released together in the support library v26…..

Solution 2:

In addition to the other correct answers, I found another element that hinders automatic positioning to make it work.

Do not use android:singleLine=true at the same time as autopositioning. Use the new android:maxLines=1 instead.

Solution 3:

I had the same problem.
I solved it by changing two lines step by step:
compiles ‘com.android.support:support-v4:26.0.1’ and
compiles ‘com.android.support:appcompat-v7:26.0.1’
To make a longer text fit, add the four options as follows:

Solution 4:

What value did you set for the android:layout_height attribute?

According to the document: If you define automatic positioning in an XML file, it is not recommended to use the wrap_content value for the layout_width or layout_height attributes in a TextView. This can lead to unexpected results.

I also did a tutorial on the automatic synchronization of TextView.

Solution No 5:

In my case, the problem was something very stupid: Although autopositioning has always worked well for me, I have the android exactly on a TextView: Namespace used instead of the : ! I wasn’t even aware of my mistake and I kept wondering why it didn’t work. Therefore, when using an AppCompat theme, always use AppCompat attributes and no native attributes.

Solution No 6:

More information about the accepted answer from @Sira Lam :

Always be careful not to inherit attributes that conflict with AutoTextSize behavior, especially android:singleLine.

Although android:maxLines or android:lines does not prevent TextView from resizing, the singleLine attribute (if set to true) completely disables the automatic resizing.

So, when you try to solve the automatic size problem, try to find the singleline attribute first, because it is sometimes inherited when the button is expanded.

Solution No 7:

Have you tried to define the four attributes described in the link you published?

For example, for example…

app: autoSizeTextType=uniform
app: autoSizeMaxTextSize=13sp
app: autoSizeMinTextSize=5sp
app: autoSizeStepGranularity=1sp

You can also try to set the width and height of wrap_content and set minWidth and maxWidth to 56dp.

As mentioned in the comments, maxlines seem to cause problems (also for me), so try removing them (self-positioning should probably fix this by reducing the text size).

Solution No 8:

Configure your TextView as follows.

Works well on Android 22, 23, 26
Autosizing of TextView doesn’t work (Android O) – here

Solution No 9:

For example, if you do not know the size of the text display. B. Draw up a linear layout and set the height or width to 0dp. then I have a solution. You must set AutoSizeTextTypeWithDefaults in the OnSizeChanged event.

Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
this.setAutoSizeTextTypeWithDefaults(AUTO_SIZE_TEXT_TYPE_UNIFORM) ;

}

Solution No 10:

Use android: maxLines=1, as Henning said.

Good luck!

android autosize textview,android:autosizetexttype,android textview font size to fit,android textview height,android textview text fill width,android:textsize,textview expand with text android,textview not showing full text android,how to set textview size programmatically in android,textview wrap_content not working

You May Also Like

How To Delete Steam Account [Windows/MAC]

Hello, friends. How are you guys doing? I want you all to…

Make navigation drawer draw behind status bar –

Development issue/problem: I am trying to create a navigation drawer from the…

How To Create A Table In Photoshop: Quick Way 2021

How to create a table in Photoshop – In addition to editing…

How to Delete Someone from Facebook Messenger

Sometimes you just don’t want to receive messages from a certain person…