Android Animation details-Frame Animation (Drawable Animation) and androiddrawable

Source: Internet
Author: User

Android Animation details-Frame Animation (Drawable Animation) and androiddrawable

Frame Animation is like a gif image. It uses some static images to achieve the animation effect.

In the Android sdkAnimationDrawableIt is specially designed for Frame Animation. Of course, Frame Animation can also be written in java code or xml, but we recommend that you write it in xml first.


<span style="font-size:18px;"><?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/market_loading_01"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_02"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_03"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_04"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_05"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_06"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_07"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_08"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_09"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_10"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_11"        android:duration="100"/>    <item        android:drawable="@drawable/market_loading_12"        android:duration="100"/></animation-list></span>

The root node of the Frame animation in xml is <animation-list> where oneshot = false is loop playback. If it is true, playing to the last image will stop playing. It is called in java

ImageView imageView;AnimationDrawable animationDrawable;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);imageView = (ImageView) findViewById(R.id.image);imageView.setBackgroundResource(R.drawable.drawable_progress);animationDrawable = (AnimationDrawable) imageView.getBackground();animationDrawable.start();

Because Frame animations are composed of a bunch of static images, they can be used as background.


Written in java code

  AnimationDrawable animationDrawable2 = new AnimationDrawable();  Drawable drawable = getResources().getDrawable(R.drawable.fengjing_1);  Drawable drawable2 = getResources().getDrawable(R.drawable.fengjing_2);  Drawable drawable3 = getResources().getDrawable(R.drawable.fengjing_3);        animationDrawable2.addFrame(drawable, 1000);        animationDrawable2.addFrame(drawable2, 1000);        animationDrawable2.addFrame(drawable3, 1000);        animationDrawable2.setOneShot(false);        imageView.setBackgroundDrawable(animationDrawable2);        animationDrawable2.start();

Well .. That's it. Frame Animation knows that it's almost done.


Project source code


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.