Android JellyBean not Recognizing getTextSize of AttriubteSet
Asked Answered
C

3

8

I am utilizing a class AutoResizeTextView I found here: https://mcmap.net/q/53230/-auto-scale-textview-text-to-fit-within-bounds

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?

Chainsmoke answered 17/7, 2012 at 12:42 Comment(0)
H
11

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.

Hemminger answered 19/7, 2012 at 9:33 Comment(1)
reducing MIN_TEXT_SIZE to 10 worked for me. // Minimum text size for this text view public static final float MIN_TEXT_SIZE = 10;Anthotaxy
B
4

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    
}
Blatant answered 24/10, 2012 at 10:26 Comment(0)
O
0

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.

Orland answered 30/8, 2012 at 8:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.