Android Animation details-Frame Animation (Drawable Animation)

Source: Internet
Author: User

Android Animation details-Frame Animation (Drawable Animation)

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.


     
     
     
     
     
     
     
     
     
     
     
     
 

The root node of the Frame animation in xml is the oneshot = false, which indicates loop playback. If it is true, the playback of the last image stops and 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.