Introduction to Android Frame Animation and android Animation

Source: Internet
Author: User

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();


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.