Home » Android » attributes – Android JellyBean not Recognizing getTextSize of AttriubteSet

attributes – Android JellyBean not Recognizing getTextSize of AttriubteSet

Posted by: admin June 15, 2020 Leave a comment

Questions:

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?

How to&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.

Answer:

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    
}

Answer:

I had seen an issue regarding Streaming.
On a streaming video when I had tried to go fwd and bwd, I had seen a restart.