Create an animation from images in expansion APK

846 Views Asked by At

So I want to create some animating ImageViews as described in :

http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

However I have been searching but couldn't find anything on this subject. Is it possible to have an item in the animation-list be an image inside an expansion APK file(a zip file). I already know how to get an image out of an Expansion APK file but I want to know if I can somehow get it into the animation-list, either programmatically or just referenced somehow in the XML file.

So my question is if this is possible? And (if possible) how I would go about doing this?

1

There are 1 best solutions below

1
rafi On BEST ANSWER

you can use different frame of image put in the drawable folder named first.png,second.png etc for animation effect and load it after certain interval of time.

create animation_list.xml and put it.

<?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/first" android:duration="210" />
    <item android:drawable="@drawable/second" android:duration="210" />
    <item android:drawable="@drawable/third" android:duration="210" />
    <item android:drawable="@drawable/fourth" android:duration="210" />
    <item android:drawable="@drawable/fifth" android:duration="210" />
    <item android:drawable="@drawable/sixth" android:duration="210" />

</animation-list>

Then in MainActivity code is.create imageview named yourImageView in the activity_main xml

import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;

public class MainActivity extends Activity {

    private AnimationDrawable frameAnimation;
    private ImageView view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        // Type casting the Image View
        view = (ImageView) findViewById(R.id.yourImageView);

        // Setting animation_list.xml as the background of the image view
        view.setBackgroundResource(R.drawable.animation_list);

        // Type casting the Animation drawable
        frameAnimation = (AnimationDrawable) view.getBackground();
        frameAnimation.start();
    }
}