我正在制作一个硬币从左边滚动的动画。
到目前为止,我可以通过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);
}
如果我同时启动它们,硬币将围绕中心显示会聚的圆周运动。
有关如何完成任务的任何建议吗?
答案 0 :(得分: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);