【问题标题】:Animation set for image view图像视图的动画集
【发布时间】:2015-07-03 08:21:57
【问题描述】:

我希望在同一个 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);

【问题讨论】:

    标签: android android-animation


    【解决方案1】:

    你不见了:

        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 之间工作。

    【讨论】:

    • 我会尝试一下,但我可能应该提到它 - 当它是唯一的动画时,fadeIn 动画可以工作。
    猜你喜欢
    • 2013-04-30
    • 2014-02-22
    • 1970-01-01
    • 2012-12-20
    • 1970-01-01
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    • 2015-04-02
    相关资源
    最近更新 更多