Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android JellyBean not Recognizing getTextSize of AttriubteSet

I am utilizing a class AutoResizeTextView I found here: https://stackoverflow.com/a/5535672/371778

This has worked great until JellyBean. It would seem that JellyBean doesn't recognize getTextSize() from the textView AttributeSet for it returns 0.0.

I tried making a custom xml attributes, but I utilize styles to use the AutoResizeTextView class and cannot include a custom namespace within styles.xml.

Any idea of a work around to get JellyBean to recognize this method?

like image 533
taraloca Avatar asked Jul 17 '12 12:07

taraloca


2 Answers

I have had the same problem and I just solved it with a fix in the AutoResizeTextView class

 /**
 * When text changes, set the force resize flag to true and reset the text size.
 */
@Override
protected void onTextChanged(final CharSequence text, final int start, final int before, final int after)
{
    mNeedsResize = true;
    mTextSize = getTextSize(); // I ADDED THIS
    // Since this view may be reused, it is good to reset the text size
    resetTextSize();
}

Now it works on 2.3, 4.0 and 4.1 the same. p.f.

like image 79
Pavel P.F. Avatar answered Nov 19 '22 02:11

Pavel P.F.


Above code works, but problems occur when AutoResizeTextView will be reused. For example in the ListView. After scaling one entry on the list some entries below could be also unnecessarily smaller. In this case onTextChanged method should look like:

@Override
protected void onTextChanged(final CharSequence text, final int start, final int before, final int after)
{
    needsResize = true;
    if (before == after)
        textSize = getTextSize();
    else
        resetTextSize(); // Since this view may be reused, it is good to reset the text size    
}
like image 34
kolczak Avatar answered Nov 19 '22 00:11

kolczak