【问题标题】:Animation for 4 different images at the same time in android在android中同时为4张不同图像制作动画
【发布时间】:2016-04-06 13:57:34
【问题描述】:

我有 4 个动画图像,例如翻译。但我想同时为它们制作动画。没有人不应该在另一个之前或之后开始。当我执行以下代码时,它不会同时开始。有人可以帮助我吗?

Animation anim=AnimationUtils.loadAnimation(getActivity(), R.anim.translate);

ImageView image1=myView.findViewById(R.id.img1);
ImageView image2=myView.findViewById(R.id.img2);
ImageView image3=myView.findViewById(R.id.img3);
ImageView image4=myView.findViewById(R.id.img4); 

image1.startAnimation(anim);
image2.startAnimation(anim);
image3.startAnimation(anim);
image4.startAnimation(anim);

【问题讨论】:

  • 然后使用ObjectAnimator / ValueAnimator,或者只使用AnimatorSet
  • @sunilsunny 不。为什么?在该答案中,为 AnimatorSet 提供了链接,您自己在答案中使用了相同的链接并问我是否检查了评论?长大了!
  • @sunilsunny problem 是什么?

标签: android animation android-animation translate-animation


【解决方案1】:

您可以尝试覆盖动画的OnAnimationStart 并在其中开始下一个动画。像这样的:

int counter = 0;
image1.startAnimation(anim);    


anim.setListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationStart(Animator animation) {
        switch(counter){
            case 0: image2.startAnimation(anim);
                counter++;
                break;
            case 1: image3.startAnimation(anim);
                counter++;
                break;
            case 2: image4.startAnimation(anim);
                counter++;
        }
    }
image1.startAnimation(anim);

每次递增计数器,以启动不同的动画。 这有点像吉米钻机,但这是我能想到的最简单的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多