The implementation of the Android frame animation and the picture too much when the Oom solution (i)

Source: Internet
Author: User

one, the sequence of statically configured frame animations in Animation_list.xml, as follows:<?xml version= "1.0"  encoding= "Utf-8"? ><animation-list xmlns:android= "http// Schemas.android.com/apk/res/android "    android:oneshot=" true " >      <item        android:drawable= "@drawable/animation_1"         android:duration= "/>    <item"         android:drawable= "@drawable/animation_2"          android:duration= "/>    <item   "      android:drawable= "@drawable/animation_3"          android:duration= "/>    <item      "   android:drawable= "@drawable/animation_4"         android: duration= "/&GT;&NBSP;&NBSP;&NBSP;&NB"sp;<item        android:drawable= "@drawable/animation_5"          android:duration= "/></animation-list>" Note: 1,android: duration= "100" refers to the duration of the corresponding frame. 2,android:oneshot configuration   If true, indicates that the animation plays only one stop at a time on the last frame, and if set to False indicates that the animation loops.
second, the method is called, as follows:Mimageview.setimageresource (r.drawable.animation_list); animationdrawable = (animationdrawable) Mimageview.getdrawable (); Animationdrawable.start (); Of course, you can also animate the playback of animations in a method, calling the following method: void Setoneshot (Boolean oneShot) : Sets whether animationdrawable executes once, true once, and false loops can also control the playback and stop of the animation in the middle, as shown below: Mimageview.setimageresource ( r.drawable.animation_list); animationdrawable = (animationdrawable) mimageview.getdrawable (); if (    Animationdrawable.isrunning ()) {//Current animationdrawable is playing animationdrawable.stop (); Stops playback of frame-wise animations.  }animationdrawable.start (); Starts playback of frame-by-frames animations. Iii. Oom Solution (i):using the above method can basically solve 20 images within the frame animation, but a lot of pictures, will report oom error,here is one of my solutions, not the best, I also feel that there are many problems, but did solve the problem,Let 's call it plan one, I believe I will think of a better solution, and then share with you1, first in the initialization, the direct initialization of two arrays, one to save each frame of the photo, another to save the duration of each frame of the picture images = new int [42]; images[0] = r.drawable.animation_0;    //animation at the beginning of animation          images[1] = R.drawable.animation_1;        &NBSP;IMAGES[2]&NBSP;=&NBSP;R.DRAWABLE.ANIMATION_2;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;IMAGES[3]  = R.drawable.animation_3;                  ...   & nbsp;     images[40] = r.drawable.animation_40;        images[41] = r.drawable.animation_41;  //animation at the end of the screen  durations = new int[40];        durations[0] = 200; How long events start after the  //event is triggered         durations[1] = 100;        DURATIONS[2] = 200; & nbsp            ......        durations[40] = 300;
2, New Myanimation class:   public class myAnimation{         private imageview mimageview;   //the corresponding layout of the broadcast square animation          private int[] mimageres;        private int [] durations;                Public myanimation (imageview pimageview, int[] pimageres,                 int[] durations)  {             this.mImageView = pImageView;             this.durations = durations;             this.mImageRes= pImageRes;                     mimageview.setimageresource (mImageRes [1]);             play (1);         }         private void play (final  int pimageno)  {             Mimageview.postdelayed (new runnable ()  {                 public void run ()  {                      Mimageview.setimageresource (Mimageres[pimageno]);                     if  (pimageno == mimageres.length-1)                         return;                      else                         play (pimageno + 1);                 }             }, durations[pimageno-1]);         }               }3, create a new Myanimation class object in the Listener event: New Myanimation (imageview, images,durations);  ------------------------------------------------- -------------------------------------------just started to learn, blogging just hope to record their own growth trajectory, welcome to the guidance.

The implementation of the Android frame animation and the picture is too large when the Oom solution (i)

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.