You do not need ImageView .
If your animation is XML Drawable , you can load it directly from Resources into the AnimationDrawable variable:
Resources res = context.getResources(); AnimationDrawable animation = (AnimationDrawable)res.getDrawable(R.drawable.anim);
Then set its borders and draw on the canvas:
animation.setBounds(left, top, right, bottom); animation.draw(canvas);
You also need to manually configure the animation to start the next scheduled interval. You can do this by creating a new callback using animation.setCallback , then instantiating android.os.Handler and using the handler.postAtTime method to add the next animation frame to the current Thread message queue.
animation.setCallback(new Callback() { @Override public void unscheduleDrawable(Drawable who, Runnable what) { return; } @Override public void scheduleDrawable(Drawable who, Runnable what, long when) {
nmelo source share