AnimationDrawable 动画不执行
mydrawable.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/fish_120" android:duration="200" />
<item android:drawable="@drawable/fish_40" android:duration="200" />
<item android:drawable="@drawable/ic_launcher" android:duration="200" />
</animation-list>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
ImageView rocketImage = new ImageView(this);
setContentView(rocketImage);
rocketImage.setBackgroundResource(R.drawable.mydrawable);
rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
rocketAnimation.start();
}
这是源码,不知道为什么动画不执行,如果把 rocketAnimation.start(); 放在
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
rocketAnimation.start();
return true;
}
return super.onTouchEvent(event);
}
动画可以执行?不知道为什么?