Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AnimationDrawable is not working on 2.3.6 android version

AnimationDrawable is not working on 2.3.6 android version.

Is there support library for older verions?

My code is:

iv = (ImageView) findViewById(R.id.splashnew);
BitmapDrawable f0 = (BitmapDrawable)getResources().getDrawable(R.drawable.s1); 
BitmapDrawable f1 = (BitmapDrawable)getResources().getDrawable(R.drawable.s2); 
BitmapDrawable f2 = (BitmapDrawable)getResources().getDrawable(R.drawable.s3);
int dur = 850; 
AnimationDrawable ad = new AnimationDrawable();
ad.addFrame(f0, dur); 
ad.addFrame(f1, dur); 
ad.addFrame(f2, dur);
ad.start();
ad.setOneShot(true);
like image 586
Asmita Avatar asked Feb 04 '13 12:02

Asmita


1 Answers

I got the answer:

You should start the animation in a runnable.

    iv.post(new Runnable(){
        public void run(){
             ad.start();
             ad.setOneShot(true); // use this if you want to run the animation only once
        }
    });
like image 164
Asmita Avatar answered Sep 28 '22 07:09

Asmita