Search code examples
androidanimationscale

How to Delay between Two frames in Frame-By-Frame Animation


Now I have four Images and I have applied frame animation on these four images

1.one

2.two

3.three

4.Go

I want to give a time delay between three and Go frame which would be a random time.

Here is my code

int d=5000;
AnimationDrawable drawable=new AnimationDrawable();
    drawable.addFrame(getResources().getDrawable(R.drawable.one), 1000);
    drawable.addFrame(getResources().getDrawable(R.drawable.two), 1000);        
    drawable.addFrame(getResources().getDrawable(R.drawable.three),d);      
    drawable.addFrame(getResources().getDrawable(R.drawable.go),d);
    drawable.setOneShot(true);
    iv3.setBackgroundDrawable(drawable);
    drawable.start();

Where iv3 is my ImageView

And I also want to give Scale animation with frame-by-frame animation on these images.

Please Help me out...

Th@nks


Solution

  • After Searching and doing lots of online stuff I believe that I cannot give delay time between two subsequent frames in frame-by-frame animation and I also cannot implement scale and frame-by-frame together.So I carried out the other way is following

        b=AnimationUtils.loadAnimation(this, R.anim.scalealpha);
    a=AnimationUtils.loadAnimation(this, R.anim.scalealpha);
            c=AnimationUtils.loadAnimation(this, R.anim.scalealpha);
            e=AnimationUtils.loadAnimation(this, R.anim.scalealpha);
    
                    a=AnimationUtils.loadAnimation(this,R.anim.scalealpha);
                    iv3.setImageResource(R.drawable.one);
                    iv3.startAnimation(a);
    
                Handler handler = new Handler();
                handler.postDelayed(new Runnable()
                {
    
                    public void run()
                    {
    
                           iv3.setImageResource(R.drawable.two);  
                           iv3.startAnimation(b);
                           Handler handler = new Handler();
                            handler.postDelayed(new Runnable()
                            {
                                public void run()
                                {
    
                                       iv3.setImageResource(R.drawable.three);
                                       iv3.startAnimation(c);
                                       Handler handler = new Handler();
                                        handler.postDelayed(new Runnable()
                                        {
                                            public void run()
                                            {
    
                                                   iv3.setImageResource(R.drawable.go);                                                                  
                                                   iv3.startAnimation(e);
                                            }}, 3000);
    
                                }}, 1000);
    
    
                    }}, 1000);  
    

    If anyone know better way than this please tell me and I would be glade to know.......... Thanks to whom who tried to solve this problem.....