2011-12-30 53 views
2

我面临的问题是Android中的帧动画。其实我有很多图像作为框架,因为我为不同的动画制作了不同的动画列表文件。在主屏幕上,我有一个背景图像,我有不同的动画按钮。我也完成了动画,但是当我点击第二次按钮时动画不起作用。意味着它只能工作一次。我不明白为什么会发生这种情况。这是我的项目的一些代码片段。Android中的帧动画中的问题

动画列表文件: -

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true"> 
<item android:drawable="@drawable/cat_angry0000" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0001" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0002" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0003" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0004" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0005" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0006" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0007" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0008" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0009" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0010" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0011" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0012" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0013" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0014" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0015" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0016" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0017" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0018" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0019" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0020" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0021" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0022" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0023" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0024" android:duration="50" /> 
<item android:drawable="@drawable/cat_angry0025" android:duration="50" /> 
</animation-list> 

代码: -

ImageView rocketImage; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.catlayout); 

    rocketImage = (ImageView) findViewById(R.id.backgroundCat); 
    rocketImage.setImageBitmap(null); 
    rocketImage.setBackgroundResource(R.anim.angry_tail_animation); 
} 

public void headButtonClicked(View v) { 
    final AnimationDrawable mailAnimation = (AnimationDrawable) mMailTab.getBackground(); 
    mMailTab.post(new Runnable() { 
    public void run() { 
     if (mailAnimation != null) mailAnimation.start(); 
    } 
    }); 
} 

headButtonClicked是我要开始动画放置一个按钮。它只工作一次。如果任何人有任何想法如何解决这个问题,请帮助我。

感谢

回答

3

动画中的XML文件中所添加的属性android:oneshot="true",这意味着你想要的动画只进行一次比赛。对于再次打它,你应该让android:oneshot="false"

UPDATE:

如果要启动动画每次你点击你要调用的animation.stop();上一个按钮,如果运行启动动画。事情是这样的,

if (frameAnimation.isRunning()) { 
     frameAnimation.stop(); 
     } 

     else { 
     frameAnimation.stop(); 
     frameAnimation.start(); 
     } 
+0

,但我想这将动画按钮点击运行,如果我改变单稳为false然后运行n个时间段。我希望当用户点击按钮时,只有动画应该开始播放。再次点击用户,然后播放这样的动画。 – Scorpion 2011-12-30 05:08:37

+1

@Scorpion ok查看我的更新回答。 – 2011-12-30 05:15:54

+0

非常感谢你..现在完成了...再次感谢! – Scorpion 2011-12-30 06:03:51