1

我正在制作一个硬币从左边滚进来的动画。

到目前为止,我可以通过 RotateAnimation 旋转它并通过 TranslateAnimation 移动它。

现在我一直试图让这两个同时运行。

{
    Animation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,-1f,Animation.RELATIVE_TO_PARENT,0,Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0);
    animation.setDuration(5000);
    setCoinAppear.addAnimation(animation);
}
{
    Animation animation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    animation.setDuration(5000);
    setCoinAppear.addAnimation(animation);
}

如果我同时启动它们,硬币将显示围绕中心的会聚圆周运动。

关于如何完成它的任何建议?

4

1 回答 1

1

您需要创建一个 AnimationSet 并将每个动画添加到集合中,如下所示:

AnimationSet rollingIn = new AnimationSet(true);

Animation moving = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,-1f,Animation.RELATIVE_TO_PARENT,0,Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0);
moving.setDuration(5000);

rollingIn.addAnimation(moving);

Animation rotating = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotating.setDuration(5000);

rollingIn.addAnimation(rotating);

setCoinAppear.startAnimation(rollingIn);
于 2012-09-27T22:20:07.870 回答