I have an animation list XML in drawables:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:duration="40" android:drawable="@drawable/animated_person_0 />
<item android:duration="40" android:drawable="@drawable/animated_person_1 />
<item android:duration="40" android:drawable="@drawable/animated_person_2 />
</animated-list>
I called the list from my content_main.xml:
<ImageView
...
android:id="@+id/animatedPerson"
android:src="@drawable/animatedperson"
...
/>
And now whatever I try with my code, I can't start the animation.
in Java it's like this:
// 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();
So Kotlin will be really similar:
// Get the background, which has been compiled to an AnimationDrawable object.
val frameAnimation: AnimationDrawable = img.background as AnimationDrawable
// Start the animation (looped playback by default).
frameAnimation.start()
Nobody asked, but i did it in ANKO, you don't need the background!? Just for somebody how whats to implement awesome animations…
I am a real ANKO fan!
loadinganim is the animation-list .xml
loadingAnim = imageView{
imageResource = R.drawable.loadinganim
}
loadingAnim = loadingView.drawable as AnimationDrawable
loadingAnim.start()
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