【问题标题】:Looping frame by frame animation逐帧循环播放动画
【发布时间】:2011-05-10 23:27:08
【问题描述】:

我试图让我的动画只运行 6 次,我设置了 oneshot="true" 并尝试循环播放动画但它不起作用,动画仍然只运行一次。

非常感谢任何帮助。

这是代码

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"  android:oneshot="true">
  <item android:drawable="@drawable/image" android:duration="100" />
  <item android:drawable="@drawable/image1" android:duration="100" />
  <item android:drawable="@drawable/image2" android:duration="100" />
  <item android:drawable="@drawable/image3" android:duration="100" />
  <item android:drawable="@drawable/image4" android:duration="100" />
 </animation-list>

.

    for (int i = 0; i < 5; i++){
        img.setBackgroundResource(R.anim.anime);
        AnimationDrawable frameAnimation = (AnimationDrawable)img.getBackground();
        frameAnimation.setCallback(img);
        frameAnimation.setVisible(true, true);
        frameAnimation.start();
   }

【问题讨论】:

  • 您需要等待每次运行完成才能开始下一次运行。
  • @Amanni:你必须将 oneshot 设置为 false 而不是 true。并尝试使用 android:repeatCount 属性

标签: android animation frame


【解决方案1】:
for (int i = 0; i < 5; i++){
    img.setBackgroundResource(R.anim.anime);
    AnimationDrawable frameAnimation = (AnimationDrawable)img.getBackground();
    frameAnimation.setCallback(img);
    frameAnimation.setVisible(true, true);
    frameAnimation.start();
}
frameAnimation.stop();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-10
    • 2023-03-31
    • 1970-01-01
    • 2021-02-02
    • 2011-09-13
    相关资源
    最近更新 更多