在属于一个动画集的ImageViews和TextViews上放置动画延迟



我已经对如何做到这一点有了一个粗略的想法,我认为这是通过每个图像视图或文本视图制作2个或更多的动画集,但代码会很长。有没有一种方法可以使代码最小化?下面是每个图像视图和文本视图的代码:

AnimationSet setA = new AnimationSet(true);
                fadeIn1.setDuration(1000);
                setA.addAnimation(fadeIn1);
                TranslateAnimation Trans1 = new TranslateAnimation(270, 0, 0, 0);
                Trans1.setDuration(1000);
                setA.addAnimation(Trans1);
                ImageView1.startAnimation(setA);
                //how do i place delay here??
                ImageView2.startAnimation(setA);
                //how do i place delay here??
                TextView1.startAnimation(setA); 
                //how do i place delay here??
                TextView2.startAnimation(setA);
                //how do i place delay here??

                setA.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }
                    @Override
                    public void onAnimationEnd(Animation animation) {
                        ImageView1.clearAnimation();
                        ImageView2.clearAnimation();
                        TextView1.clearAnimation();
                        TextView2.clearAnimation();
                    }
                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }
                });

可以通过使用处理程序来设置延迟。如:

               new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                     ImageView1.startAnimation(setA);
                }
            }, 2000);
          new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                     ImageView2.startAnimation(setA);
                }
            }, 4000);

最新更新