Introduction to Android Frame Animation and android Animation
1. Frame Animation
Put multiple images together and play the animation continuously, similar to GIF
2. Implementation Principle
Put an image into an animation List in sequence, set the display duration of each image, and then play it to form an animation.
3. XML file
Create an anim_logo.xml file in the res/anim folder. The specific content is as follows:
<?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/ic_logo1" android:duration="500" /> <item android:drawable="@drawable/ic_logo2" android:duration="500" /> <item android:drawable="@drawable/ic_logo3" android:duration="500" /> <item android:drawable="@drawable/ic_logo4" android:duration="500" /></animation-list>
Each item corresponds to an image. android: duration can set the display duration of the image.
Android: oneshot
False: loop playback
True: play once
4. Call an animation
<ImageView android:id="@+id/iv_click_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txt_status" android:paddingLeft="15dp" android:layout_marginTop="15dp" android:layout_centerHorizontal="true" android:background="@anim/anim_logo" />
5. Start Animation
AnimationDrawable anim = (AnimationDrawable) mLogoImg.getBackground(); anim.start();
6. Stop the animation.
AnimationDrawable anim = (AnimationDrawable) mLogoImg.getBackground(); anim.stop();