2011-09-30 9 views
29

OnTouch de un ImageView estoy empezando un fundido en la animación:Animación Android Listener

myImageView.setOnTouchListener(new View.OnTouchListener() { 
    public boolean onTouch(View v, MotionEvent event) { 
    v.startAnimation(fadeInAnimation); 

Sé que es necesario un oyente animación para averiguar cuando la animación se ha completado, pero ¿cómo agrego el presente para que yo puede obtener la vista de que la animación acaba de completarse ... Quiero establecer la visibilidad de la vista una vez finalizada la animación.

Gracias

+0

lo que es su problema? –

+0

ser específico –

+1

Quiero saber cómo agregar un oyente de animación a una vista de imagen – beans

Respuesta

80

Creo que necesita esto.

fadeInAnimation.setAnimationListener(new Animation.AnimationListener() { 
    @Override 
    public void onAnimationStart(Animation animation) { 

    } 

    @Override 
    public void onAnimationEnd(Animation animation) { 

    } 

    @Override 
    public void onAnimationRepeat(Animation animation) { 

    } 
}); 
12

Si sólo necesita una acción final bastaría con usar .withEndAction(Runnable)

fadeInAnimation.withEndAction(new Runnable() { 
    @Override 
    public void run() { 
     ... do stuff 
    } 
}) 
+3

Solo se puede usar en el nivel API 16 o superior – Roel

+0

Apuntar al nivel API 22 y no veo que 'withEndAction()' esté disponible con TranslateAnimation clase –

+0

@Roel ¿podría referirme a mi enlace? quiero verificar el nivel de 'api' –