2012-07-17 9 views
8

Estoy utilizando una clase AutoResizeTextView he encontrado aquí: https://stackoverflow.com/a/5535672/371778Android JellyBean no reconocer getTextSize de AttriubteSet

Esto ha funcionado muy bien hasta JellyBean. Parece que JellyBean no reconoce getTextSize() de textView AttributeSet porque devuelve 0.0.

Intenté crear atributos xml personalizados, pero utilizo estilos para usar la clase AutoResizeTextView y no puedo incluir un espacio de nombres personalizado en styles.xml.

¿Alguna idea de cómo evitar que JellyBean reconozca este método?

Respuesta

11

he tenido el mismo problema y acabo resuelto con una solución en la clase AutoResizeTextView

/** 
* 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(); 
} 

ahora funciona en 2.3, 4.0 y 4.1 de la misma. p.f.

+0

acaba de intentar esto y se resuelve el problema! – pandre

+0

reduciendo MIN_TEXT_SIZE a 10 trabajado para mí. // Tamaño de texto mínimo para esta vista de texto float flotante estático público MIN_TEXT_SIZE = 10; –

0

He visto un problema relacionado con Streaming. En un video de transmisión cuando intenté fwd y bwd, había visto un reinicio.

4

El código anterior funciona, pero ocurren problemas cuando AutoResizeTextView se reutilizará. Por ejemplo, en ListView. Después de escalar una entrada en la lista, algunas entradas a continuación también podrían ser innecesariamente más pequeñas. En este caso OnTextChanged método debe ser similar:

@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  
} 
Cuestiones relacionadas