Android frame animation, anti-Oom, save over 10 times times more resources than original vivid album

Source: Internet
Author: User

2015 project received a demand for a wizard animation, the animation of a total of 60 pictures, at that time using the full-A33 Development Board, through the use of Android animation set implementation, and then think of this way to achieve, the effect is smooth. Then write an open source project for your reference.

The following two ways to implement frame animation, using the same 80 280x280 PNG pictures to perform animation, resource occupancy comparison:

Code Address:
Https://github.com/ansen360/FrameAnimation
Sample effect:

Http://oma689k8f.bkt.clouddn.com/note/3/4.gif

Android animation set for frame animation
    • 1 Create an animation set in the drawable directory Animalist.xml
<?xml version= "1.0" encoding= "Utf-8"?><animation-list xmlns:android="Http://schemas.android.com/apk/res/android" android:oneshot="false">        <!--80 photos played via Android animation set--    <itemandroid:drawable="@mipmap/c_1"android:duration="50" />                    <itemandroid:drawable= "@mipmap/c_2"android:duration=" " />                     <!--omitted ...-    <itemandroid:drawable="@mipmap/circle_19"android:duration="50" />                    <itemandroid:drawable="@mipmap/circle_20"android:duration=  "/>"                 </animation-list>
    • 2 Use this drawable in the layout file ImageView
<?xml version= "1.0" encoding= "Utf-8"?><linearlayout  xmlns: Android  = "http://schemas.android.com/apk/res/android"  xmlns:app  =" Http://schemas.android.com/apk/res-auto " Span class= "Hljs-attribute" >xmlns:tools  = "Http://schemas.android.com/tools"     android:layout_width  = "match_parent"  android:layout_height  = "match_parent"  tools:context  = " Com.ansen.frameanimation.sample.MainActivity ";     <ImageViewandroid:id= "@+id/image"android:layout_width="Wrap_ Content "android:layout_height="wrap_content "android:src=" @drawable/ Animlist " />                                </linearlayout>
    • 3 Call in code, start animation
    ImageView image = (ImageView) findViewById(R.id.image);    AnimationDrawable animationDrawable = (AnimationDrawable) image.getDrawable();        animationDrawable.start();

The animation starts the system resource usage as follows:

Manually triggering GC, memory footprint almost unchanged

Frameanimation Implementing Frame Animations
    • 1 define the resource files that need to play the animation, define the resources in the arrays file, or define them in the code
<?xml version= "1.0" encoding= "Utf-8"?><resources>    <!--80 photos played via Frameanimation-    <array name="C">        <item>@mipmap/c_1</Item>        <item>@mipmap/c_2</Item>        <!--omitted ...-        <item>@mipmap/circle_19</Item>        <item>@mipmap/circle_20</Item>    </array></Resources>

Gets an array of resources after the definition (the array of resource files can be directly defined in the code, ignoring the previous step):

    privateint[] getRes() {        TypedArray typedArray = getResources().obtainTypedArray(R.array.c);        intlen = typedArray.length();        intnewint[len];        for (int0len; i++) {            resId[i] = typedArray.getResourceId(i, -1);        }        typedArray.recycle();        return resId;    }
    • 2 call in code, start animation
ImageView image = (ImageView) Findviewbyid (r.id.image); Frameanimation frameanimation =NewFrameanimation (image, Getres (), -,true); Frameanimation.setanimationlistener (NewFrameanimation.animationlistener () {@Override         Public void Onanimationstart() {LOG.D (TAG,"Start"); }@Override         Public void Onanimationend() {LOG.D (TAG,"End"); }@Override         Public void onanimationrepeat() {LOG.D (TAG,"Repeat"); }    });

The animation starts the system resource usage as follows:

Manually triggering GC with significant memory footprint changes

Android frame animation, anti-Oom, save over 10 times times more resources than original vivid album

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.