我下面http://developer.android.com/guide/topics/graphics/view-animation.html#frame-animation有细微的变化。我已决定把动画循环,并希望它从一开始就开始。
I am following http://developer.android.com/guide/topics/graphics/view-animation.html#frame-animation with minor changes. I have decided to make the animation loop and want it to start from the get-go.
我的动画是绘制/ listening.xml:
My animation is at drawable/listening.xml:
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="@drawable/l_01"
android:duration="200" />
<item
android:drawable="@drawable/l_02"
android:duration="200" />
<item
android:drawable="@drawable/l_03"
android:duration="200" />
</animation-list>
和我的初始化code:
and my init code:
@Override public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
animImg = (ImageView)findViewById(R.id.listen_anim);
animImg.setBackgroundResource(R.drawable.listening);
anim = (AnimationDrawable) animImg.getBackground();
anim.start();
};
我看到的是第一帧,没有其他的图像。
All I see is the first frame and no other images.
在onResume()运行此:
Run this in onResume():
class AnimTask extends AsyncTask<String, String,String> {
Activity act;
AnimTask(Activity act) {
this.act = act;
}
@Override
protected String doInBackground(String... params) {
act.runOnUiThread(new Runnable() {
public void run(){
animImg = (ImageView)findViewById(R.id.listen_anim);
animImg.setBackgroundResource(R.drawable.listening);
anim = (AnimationDrawable) animImg.getBackground();
anim.start();
}
});
return null;
}
}