我想通过更改ImageView中的帧来创建一个简单的动画.我不想使用AnimationDrawable,因为我需要在帧更改或动画停止时接收事件,以便能够向后播放,重新启动它等等.
我的问题是虽然setImageDrawable被调用(在主线程上),但帧实际上并没有改变事件.所以每一件事似乎工作得很好,除了框架不会改变(实际上只绘制一个框架,第一个框架).
所以我的代码:
public class AnimatedImageView extends ImageView implements Animatable, Runnable {
private static final String TAG = "AnimatedImageView";
public static interface AnimationEventsListener {
void animationDidChangeFrame(AnimatedImageView animatedImageView);
void animationDidStop(AnimatedImageView animatedImageView);
}
/* frames - ress ids */
private int[] mFrameResIds;
/* current frame index */
private int mCurrentFrameIdx;
/* number of the current repeat */
private int loopIndex;
/* number of animation repetiotions, 0 for infinite */
private int mNumOfRepetitions;
/* if animation is playing */
private boolean playing;
/* …
Run Code Online (Sandbox Code Playgroud) animation android android-imageview animationdrawable android-drawable