开发者

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

开发者 https://www.devze.com 2023-03-20 23:25 出处:网络
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.

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


see this it works fine for me.

  public class MainActivity extends ActionBarActivity {
ImageView view;
AnimationDrawable Anim;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    view = (ImageView) findViewById(R.id.ivAnimation);
    view.setId(1);
    view.setBackgroundResource(R.drawable.image);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (view.getId() == 1) {
                animationStart();
                view.setId(2);
            } else {
                view.setBackgroundResource(R.drawable.image);
                view.setId(1);

            }
        }

        private void animationStart() {
            try {
                BitmapDrawable frame1 = (BitmapDrawable) getResources()
                        .getDrawable(R.drawable.one);
                BitmapDrawable frame2 = (BitmapDrawable) getResources()
                        .getDrawable(R.drawable.two);
                BitmapDrawable frame3 = (BitmapDrawable) getResources()
                        .getDrawable(R.drawable.three);

                BitmapDrawable frame4 = (BitmapDrawable) getResources()
                        .getDrawable(R.drawable.four);
                BitmapDrawable frame5 = (BitmapDrawable) getResources()
                        .getDrawable(R.drawable.five);
                BitmapDrawable frame6 = (BitmapDrawable) getResources()
                        .getDrawable(R.drawable.six);

                Anim = new AnimationDrawable();
                Anim.addFrame(frame1, 200);
                Anim.addFrame(frame2, 200);
                Anim.addFrame(frame3, 200);
                Anim.addFrame(frame4, 200);
                Anim.addFrame(frame5, 200);
                Anim.addFrame(frame6, 200);
                Anim.setOneShot(false);
                view.setBackgroundDrawable(Anim);
                final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {

                    public void run() {

                        Anim.start();

                    }
                }, 100);

            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    });
}

}


Here is the example : check this

It seems that you have to write the animation duration in XML like:

<item android:drawable="@drawable/wheel0" android:duration="50" />

Hope it helps.

EDIT: : check this link too.


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.....

0

精彩评论

暂无评论...
验证码 换一张
取 消