如何运行一系列动画?动画集让我失望
我有一个自定义视图Dial
。此视图有一个自定义动画 DialAnimation
,它是作为 Dial
的嵌套类编写的。下面是我的 Activity
中的代码,它实例化 Dial
并尝试在其上执行一系列动画。运行代码时,屏幕上只能看到其中一个动画。我在这里缺少什么?
Dial dial = (Dial) findViewById(R.id.dial);
DialAnimation anim1 = dial.new DialAnimation(0, 90, 3000);
DialAnimation anim2 = dial.new DialAnimation(180, 360, 3000);
anim2.setStartOffset(3500);
AnimationSet set = new AnimationSet(false);
set.addAnimation(anim1);
set.addAnimation(anim2);
dial.startAnimation(set);
I have a custom view Dial
. This view has a custom animation DialAnimation
that was written as a nested class of Dial
. Below is the code from my Activity
that instantiates Dial
and attempts to perform a sequence of animations on it. When the code is run, only one of the animations is seen onscreen. What am I missing here?
Dial dial = (Dial) findViewById(R.id.dial);
DialAnimation anim1 = dial.new DialAnimation(0, 90, 3000);
DialAnimation anim2 = dial.new DialAnimation(180, 360, 3000);
anim2.setStartOffset(3500);
AnimationSet set = new AnimationSet(false);
set.addAnimation(anim1);
set.addAnimation(anim2);
dial.startAnimation(set);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种方法是在第一个动画上设置一个 AnimationListener 并重写 onAnimationEnd() 以使其启动序列中的下一个动画。那看起来像这样:
one way to do it would be to set an AnimationListener on the first animation and override the onAnimationEnd() to make it start the next animation in the sequence. That would look something like this:
在 doinbackground() 方法中尝试动画列表器,这将按顺序更新您的动画
..或者您可以在应用程序中使用简单的线程。
try animation listner in doinbackground() method this will update your animation in sequence
..OR u can use simple thread in you application .
为每个动画添加 .setDuration(3500) 方法,并确保持续时间的时间与第二个动画的 .setStartOffset(3500) 方法的时间匹配。
Add a .setDuration(3500) method to each animation and ensure that the time for the duration and the time for the .setStartOffset(3500) method for the secondanimation match.