I am looking at the documentation for animation-list and the XML layout is straight forward, but I am confused how they deal with it in the code.
In that page they have something like:
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.spin_animation);
// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
// Start the animation (looped playback by default).
frameAnimation.start();
But they never reference spinning_wheel_image anywhere in the XML they show, nor the spin_animation ….the id for the spin snippet in their examples is “selected”
So I am wondering where those two references come from? And why the actual id of the XML snippet which is “selected” is never used?
Thanks!
EDIT:
I put my animations xml into a file called animation.xml
And in the code now I have this:
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.animation);
// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
// Start the animation (looped playback by default).
frameAnimation.start();
spinning_wheel_imageis the ID of anImageView, presumably from a layout resource used withsetContentView()or aLayoutInflater.That is presumably a typo — there is no
android:idforAnimationDrawable. At least, it is not in the documentation. The name of an animation resource is based on the filename, and the filename isspin_animation .xml.