2016-06-24 9 views
0

Ich versuche, ein Bild ständig ein- und auszublenden, aber es wird nur ein- und ausgeblendet. Wie kann ich es ständig wiederholen? Hier ist der Code:Ein- und Ausblenden eines Bildes in der Android-App

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); 

Antwort

2

Mit Animator, es ist ziemlich einfach:

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

Danke das hat funktioniert: D –

0

Sie Ihre Animation wiederholen sollte:

animation.setRepeatCount(Animation.INFINITE); 
Verwandte Themen