2016-06-24 2 views
0

J'essaie de faire une image fondu en et en permanence, mais il se fanent juste une fois et sortir. Comment puis-je le faire répéter en permanence? Voici le code:Fondu dans et hors une image constamment dans l'application Android

Animation fadeIn = new AlphaAnimation(0, 1); 
    fadeIn.setDuration(1000); 

    Animation fadeOut = new AlphaAnimation(1, 0); 
    fadeOut.setStartOffset(1000); 
    fadeOut.setDuration(1000); 

    AnimationSet animation = new AnimationSet(true); 
    animation.addAnimation(fadeIn); 
    animation.addAnimation(fadeOut); 
    ImageView loading = (ImageView)findViewById(R.id.loading); 
    loading.startAnimation(animation); 

Répondre

2

Avec Animator, il est assez facile:

Animator alphaAnimator = ObjectAnimator.ofFloat(loading, View.ALPHA, 0f, 1f); 
alphaAnimator.setDuration(1000); 
alphaAnimator.setRepeatMode(ValueAnimator.REVERSE); 
alphaAnimator.setRepeatCount(ValueAnimator.INFINITE); 
alphaAnimator.start(); 
+0

Merci qui a fonctionné: D –

0

Vous devez répéter votre animation:

animation.setRepeatCount(Animation.INFINITE);