Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoTextView max size issue

I am getting this crash in my app Caused by:

java.lang.IllegalArgumentException: Maximum auto-size text size (24.674995px) is less or equal to minimum auto-size text size (31.5px)

With auto TextView. How to handle such scenarios gracefully where this case occurs.

like image 374
Praveen Pandey Avatar asked Feb 04 '23 23:02

Praveen Pandey


2 Answers

I had the same exact issue come up today. Generally speaking whenever I have an issue I can't explain it's a Samsung device. This is no different just like you said. Basically the default theme on Samsung phones sets a minimum size. For us the solution was to specifically add the autoSizeMinTextSize="12dp".

like image 143
TheHebrewHammer Avatar answered Feb 06 '23 15:02

TheHebrewHammer


Here's another solution depending on your needs and exactly why this is failing for you. The problem is that the user has changed the default font scaling size in the display settings of their device (specifically, they have increased the scale to make the text bigger). Thus the size of the text is larger than the maximum you specified, because the default minimum (since you did not specify a minimum, and that default IS scaled by the user preference) is larger than your maximum.

Specifying a minimum is only the solution if you want to ignore the user's scaling preference. In some cases that is required (in my project we simply cannot honor the user's desired text size in a specific case because that text is bound to visual elements with a fixed size).

The "proper" solution, in that it will honor the user's scaling preference, is to use sp units (which are density-independent like dp, but they ARE scaled by user preference) instead of dp units. If you do this you can still only specify a maximum font size, since that maximum will accordingly be scaled along with the default minimum which you did not specify.

So to sum up, you should always use sp units to specify sizes related to text, unless you specifically want to ignore user scaling due to your layout requirements.

Also, this is easy to test. Just go into Settings->Font and screen zoom->Font Size and set it to "Huge". You should already be testing your layouts against these kinds of variables anyway.

like image 29
Dan Avatar answered Feb 06 '23 14:02

Dan