I have an animation.xml with 4 frames.
<?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/male01a" android:duration="4000" />
<item android:drawable="@drawable/male01b" android:duration="1100" />
<item android:drawable="@drawable/male01c" android:duration="1100" />
<item android:drawable="@drawable/male01d" android:duration="300" />
</animation-list>
Is there anyway I can use some sort of variable here for each drawable? Much like using "@string/animation1" where animation1 points to "@drawable/male01a" in Strings.xml. But I need some way to change the drawables, say to male02a, in the code.
You can dynamically add frames to your animation using the method addFrame().
Example:
ImageView imview = (ImageView) findViewById(R.id.ivImage);
AnimationDrawable ad = (AnimationDrawable) imview.getDrawable();
Drawable frame = Drawable.createFromPath("your image path");
ad.addFrame(frame, 200);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With