2015-07-02 266 views
0

我想要在同一个ImageView上播放多个动画。我正在使用动画集,但它永远不会淡入。但它确实会旋转。有人能告诉我我错过了什么吗?为图像视图设置的动画

AnimationSet s = new AnimationSet(false);//false mean dont share interpolators 

    Animation fadeIn = new AlphaAnimation(0, 1); 
    fadeIn.setInterpolator(new DecelerateInterpolator()); // add this 
    fadeIn.setDuration(fadeInDuration); 
    iv.setAnimation(fadeIn); 
    iv.startAnimation(fadeIn); 


    RotateAnimation anim = new RotateAnimation(0.0f, 360.0f , Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f); 
    anim.setInterpolator(new LinearInterpolator()); 
    anim.setRepeatCount(Animation.INFINITE); 
    anim.setDuration(800); 

    s.addAnimation(fadeIn); 
    s.addAnimation(anim); 
    iv.startAnimation(s); 

回答

0

你缺少:

Animation fadeIn = new AlphaAnimation(0, 1); 
    fadeIn.setInterpolator(new DecelerateInterpolator()); // add this 
    fadeIn.setDuration(fadeInDuration); 
    fadeIn.setFillEnabled(true); // to apply setFillBefore and setFillAfter 
    fadeIn.setFillBefore(true); // it means that at start of animation you set alpha="0" 
    fadeIn.setFillAfter(false); 
    iv.setAnimation(fadeIn); 
    iv.startAnimation(fadeIn); 

而且,在你的风格,你必须删除alpha="0"

AlphaAnimation是在图像上工作,因为它是。所以如果你设置了alpha="0"它在这个0之间起作用。如果alpha="1"或没有它(当样式默认为alpha="1"),它在0-1之间起作用。

+0

我会尝试一下,但我可能应该提到它 - 当它是唯一的动画时,fadeIn动画就起作用。 – Aadithya

相关问题