4

Problem specific to the android about frame-by-frame animation

 2 years ago
source link: https://www.codesd.com/item/problem-specific-to-the-android-about-frame-by-frame-animation.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Problem specific to the android about frame-by-frame animation

advertisements

I'm trying to perform frame by frame animation in android. For this task I created an xml file called "anim.xml" like this:

    <?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/square0" android:duration="100" />
    <item android:drawable="@drawable/square1" android:duration="100" />
    <item android:drawable="@drawable/square2" android:duration="100" />
    <item android:drawable="@drawable/square3" android:duration="100" />
    <item android:drawable="@drawable/square4" android:duration="100" />
    <item android:drawable="@drawable/square5" android:duration="100" />
    </animation-list>

Then at a frame layout that I have defined, I tried to set it as background and start it at onCreate like this:

    FrameLayout imgView = (FrameLayout)findViewById(R.id.frameLayout1);
    imgView.setBackgroundResource(R.drawable.anim);
    AnimationDrawable anim = (AnimationDrawable) imgView.getBackground();
    anim.start();

What I'm experiencing is the first frame only, but what I'm going for is an animation of squares to be on a loop. Do you have any opinions regarding what I have done wrong ?

Cheers.


I've experience issues before when trying to get animations to start in the onCreate method. Try repalcing your last line with something like:

imgView.post(new Runnable()
    {
        @Override
        public void run()
        {
            anim.start();
        }
    });

This will essentialy make you animation start after onCreate has executed.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK