【问题标题】:Chained rotate animation not functioning链式旋转动画不起作用
【发布时间】:2013-05-01 04:55:55
【问题描述】:

我正在尝试使用旋转来显示左右摇晃的外观。我试图以编程方式定义动画,并按照this question 中的建议使用animationset 循环它。但是在执行时,代码似乎根本没有做任何事情。

AnimationSet set = new AnimationSet(true);

RotateAnimation rotright = new RotateAnimation(0.0f, 20.0f,
        Animation.RELATIVE_TO_SELF, 0.9f, Animation.RELATIVE_TO_SELF, 0.5f);
rotright.setDuration(0);
set.addAnimation(rotright);

RotateAnimation rotleft = new RotateAnimation(0.0f, 340.0f,
        Animation.RELATIVE_TO_SELF, 0.9f, Animation.RELATIVE_TO_SELF, 0.5f);
rotleft.setDuration(0);
set.addAnimation(rotleft);

blender.startAnimation( set );
}
};

任何关于我到底是如何搞砸的线索将不胜感激。

【问题讨论】:

    标签: android android-animation


    【解决方案1】:
    rotright.setDuration(0);
    
    rotleft.setDuration(0);
    

    您已将两个动画的持续时间设置为 0,有效地创建了 instant 旋转,这导致根本没有动画。尝试设置一些大于零的值 - 请记住您设置的是毫秒。

    【讨论】:

    • 非常感谢。如果我可以扩展我的问题,它还没有循环。知道为什么吗?
    • @user1398478:您是否在您的AnimationSet 上设置了setRepeatMode(int)?我在您的原始代码 sn-p 中没有看到它。您可以传入Animation.RESTARTAnimation.REVERSE,具体取决于所需的效果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-05
    • 2015-10-26
    相关资源
    最近更新 更多