Hi all
The Android docs shows a way to create an XML definition of an animation like this:
I have been trying to create a Drawable from this XML like this
And then draw it on my canvas in my SurfaceView like this
It draws the first image - but it doesn't animate through the images specified in the XML.
I thought maybe I needed to make it an AnimationDrawable like this
But it still didn't animate. So finally I thought maybe I need to call start() on it, but that gives me an error.
Am I just barking up the wrong tree here? Is it not possible to draw an animation to a canvas in this way? I have seen a tutorial which uses a sprite sheet and the setbounds method to do this, so maybe it's just not possible using the XML route?
The Android docs shows a way to create an XML definition of an animation like this:
PHP:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/img1" android:duration="200" />
<item android:drawable="@drawable/img2" android:duration="200" />
<item android:drawable="@drawable/img3" android:duration="200" />
</animation-list>
I have been trying to create a Drawable from this XML like this
PHP:
Drawable sprite = (Drawable) getResources().getDrawable(R.anim.sprite);
And then draw it on my canvas in my SurfaceView like this
PHP:
sprite.draw(canvas);
It draws the first image - but it doesn't animate through the images specified in the XML.
I thought maybe I needed to make it an AnimationDrawable like this
PHP:
AnimationDrawable sprite = (AnimationDrawable) getResources().getAnimation(R.anim.sprite);
But it still didn't animate. So finally I thought maybe I need to call start() on it, but that gives me an error.
Am I just barking up the wrong tree here? Is it not possible to draw an animation to a canvas in this way? I have seen a tutorial which uses a sprite sheet and the setbounds method to do this, so maybe it's just not possible using the XML route?
. 