2011-10-06 9 views
6

Quiero ser capaz de hacer una animación de texto y cambiar el tamaño del texto en un TextView. Leí que hay animaciones de propiedades en Android, pero si alguien conoce un código simple que puede hacer esto por mí o un ejemplo en alguna parte, lo agradeceré profundamente. ¡Gracias de antemano!animación del tamaño de texto de TextView

+0

Relacionados [Animación del tamaño de texto de TextView de Android y no todo el TextView] (// stackoverflow.com/a/30324368) – Tushar

Respuesta

15

scale.xml

<?xml version="1.0" encoding="utf-8"?> 
<set 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <scale 
      android:fromXScale="1.0" 
      android:fromYScale="1.0" 
      android:toXScale="2.0" 
      android:toYScale="2.0" 
      android:duration="3000"></scale> 
</set> 

una función en una actividad:

private void RunAnimation() 
{ 
    Animation a = AnimationUtils.loadAnimation(this, R.anim.scale); 
    a.reset(); 
    TextView tv = (TextView) findViewById(R.id.firstTextView); 
    tv.clearAnimation(); 
    tv.startAnimation(a); 
} 

extraído y modificado a partir de here

+1

Gracias, esto me ayudó mucho. Pero también estaba deambulando, ¿podría hacerse con una animación de la propiedad en el texto y no con la vista del texto completo? – Sandra

+0

'scale.xml' pasa por debajo de **/res/anim/** – gnB

3

¿Qué tal this link? En particular, los ejemplos de escala. Proporciona código fuente y videos para varios tipos diferentes de animaciones de Android.

+1

Gracias por su r rápido respuesta y para el enlace. Lo revisaré. – Sandra

+0

No confíe en el enlace ya que puede disminuir en el futuro. Agregue una parte relevante del enlace a la respuesta. –

5
Animation animation=new TranslateAnimation(0,480,0,0); 
animation.setDuration(5000); 
animation.setRepeatMode(Animation.RESTART); 
animation.setRepeatCount(Animation.INFINITE); 
text.startAnimation(animation); 
// applying animation to textview object.. 

Si está utilizando evento de botón para mostrar la animación a continuación, poner el código dentro de onClick() de lo contrario utiliza el método de anulación onWindowFocusChanged (HasFocus booleano) para iniciar la animación

1
clase

Uso ValueAnimator en el androide

final float startSize = o; // Size in pixels 
    final float endSize = 30; 
    final int animationDuration = 1000; // Animation duration in ms 

    ValueAnimator animator = ValueAnimator.ofFloat(startSize, endSize); 
    animator.setDuration(animationDuration); 

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 
     @Override 
     public void onAnimationUpdate(ValueAnimator valueAnimator) { 
      float animatedValue = (float) valueAnimator.getAnimatedValue(); 
      tv.setTextSize(animatedValue); 
     } 
    }); 

    animator.start(); 

se refiere este enlace ValueAnimator

Otra solución es que se aplican animación escala en Textview o su trazado padre

ScaleAnimation scaleAnimation = new ScaleAnimation(0.7f, 1.1f, 0.7f, 1.1f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, 
        ScaleAnimation.RELATIVE_TO_SELF, 0.5f); 
scaleAnimation.setDuration(600); 
viewZoom.startAnimation(scaleAnimation); 
+0

Código copiado de [esta respuesta] (http://stackoverflow.com/a/30324368/2025923) – Tushar

+0

Funciona sin problemas incluso en OnePlus3T ( –

Cuestiones relacionadas