如何在逐帧动画中延迟两帧之间的延迟

时间:2011-07-15 08:42:25

标签: android animation scale

现在我有四张图片,我在这四张图片上应用了帧动画

1.one

2.两

3.three

4.Go

我想在三帧和Go帧之间给出时间延迟,这将是一个随机时间。

这是我的代码

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();

其中iv3是我的ImageView

我还想在这些图像上使用逐帧动画制作缩放动画。

请帮帮我......

钍@ NKS

3 个答案:

答案 0 :(得分:1)

看到它对我来说很好。

  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();
            }

        }
    });
}

}

答案 1 :(得分:0)

以下是示例:check this

似乎你必须用XML编写动画持续时间,如:

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

希望它有所帮助。

编辑::同时检查this链接。

答案 2 :(得分:0)

在搜索和做大量在线资料之后,我相信我不能在逐帧动画的两个后续帧之间给出延迟时间,而且我也无法一起实现比例尺和逐帧。所以我执行了其他方式如下

    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);  

如果有人知道比这更好的方法请告诉我,我会想知道.......... 感谢谁试图解决这个问题......

相关问题