Hi,
I've had the very same problem just yesterday.
After digging through the framework source, the solution was quiet
easy:
On scheduling the next frame the view tries to verify the drawable
(this is the default implementation for the View class)
6733 /**
6734 * If your view subclass is displaying its own Drawable
objects, it should
6735 * override this function and return true for any Drawable it
is
6736 * displaying. This allows animations for those drawables to
be
6737 * scheduled.
6738 *
6739 * <p>Be sure to call through to the super class when
overriding this
6740 * function.
6741 *
6742 * @param who The Drawable to verify. Return true if it is
one you are
6743 * displaying, else return the result of calling
through to the
6744 * super class.
6745 *
6746 * @return boolean If true than the Drawable is being
displayed in the
6747 * view; else false and it is not allowed to animate.
6748 *
6749 * @see #unscheduleDrawable
6750 * @see #drawableStateChanged
6751 */
6752 protected boolean verifyDrawable(Drawable who) {
6753 return who == mBGDrawable;
6754 }
For the animation to work, your view needs to overwrite the
verifyDrawable() method.
Something like this should work:
protected boolean verifyDrawable(Drawable who) {
return (who != null);
}
Also be sure to call the start() method of your animation after the
surface has ben created. (i.e. SurfaceView.getHandler() does not
return null)
Greetings Andre
On 27 Aug., 17:17, jeka <[email protected]> wrote:
> Here is myAnimationDrawable:
>
> res/anim/my_anim.xml
> <?xml version="1.0" encoding="utf-8"?>
> <animation-list xmlns:android="http://schemas.android.com/apk/res/
> android" android:oneshot="false">
> <item android:drawable="@drawable/empty" android:duration="250" />
> <item android:drawable="@drawable/nont_empty"
> android:duration="250" />
> </animation-list>
>
> Here is how I use it from the drawing thread, which is implemented as
> an inner class of my SurfaceView subclass:
>
> AnimationDrawablead = (AnimationDrawable) getResources().getDrawable
> (R.anim.my_anim);
> ad.setCallback(MyView.this);
> ad.draw(canvas);
> ad.start();
>
> this only draws the first frame of the animation and nothing else.
>
> Thank you.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---