gpt4 book ai didi

安卓动画 "Rolling in"

转载 作者:行者123 更新时间:2023-11-30 04:04:35 29 4
gpt4 key购买 nike

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

到目前为止,我可以通过 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);
}

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

关于如何完成它有什么建议吗?

最佳答案

您需要创建一个 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);

关于安卓动画 "Rolling in",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11946156/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com