【问题标题】:Android animation does not repeatAndroid动画不重复
【发布时间】:2020-06-05 00:51:57
【问题描述】:

我正在尝试制作可以重复多次(或无限次)的简单动画。
android:repeatCount 好像不行!
这是我来自/res/anim/first_animation.xml的动画资源:

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false"
    android:repeatCount="infinite"
    >
    <scale
        android:interpolator="@android:anim/decelerate_interpolator"
        android:duration="500"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:toXScale="1.2"
        android:toYScale="1.2"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fillAfter="false" />
    <scale
        android:interpolator="@android:anim/accelerate_interpolator"
        android:startOffset="500"
        android:duration="500"
        android:fromXScale="1.2"
        android:fromYScale="1.2"
        android:toXScale="1.0"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fillAfter="false" />
</set>

首先,它应该在 500 毫秒内将图像从 1.0 缩放到 1.2。
然后在 500 毫秒内将其缩放回 1.0。
以下是我的使用方法:

Animation firstAnimation = AnimationUtils.loadAnimation(this, R.anim.first_animation);
imgView.startAnimation(firstAnimation);

它进行一个循环然后结束。
它按比例放大,然后按比例缩小,然后停止。

我怎样才能按预期工作?

【问题讨论】:

  • 你的 java 代码中的 imgView 是什么?

标签: android animation


【解决方案1】:

更新:早在 2011 年 9 月,一位 Android 工程师就已大部分修复了此问题。在 XML 中被忽略的属性现在可以工作了,除了 repeatCountfillEnabled 仍然被忽略(出于某种原因故意)。这意味着不幸的是,重复AnimationSet 仍然不容易。

有关详细信息,请参阅updated docs 中的概述(解释哪些属性被忽略、哪些工作以及哪些被传递给子级)。要更深入地了解 fillAfterfillBeforefillEnabled 的实际作用,请参阅工程师 (Chet Haase) 的博客文章 here


原答案

扩展 Pavel 和其他人的答案:&lt;set&gt; 标签确实存在可笑的错误。它无法正确处理repeatCount 和许多其他属性。

我花了几个小时弄清楚它可以处理和不能处理的问题,并在此处提交了错误报告/问题:Issue 17662

总之(这涉及AnimationSets):

setRepeatCount() / android:repeatCount

此属性(以及 repeatMode)在代码或 XML 中不起作用。这使得重复整套动画变得困难。

setDuration() / android:duration

在代码 WORKS 中的 AnimationSet 上设置此项(覆盖子动画的所有持续时间),但当包含在 XML 中的标记中时则不行

setFillAfter() / android:fillAfter

这适用于标记的代码和 XML。奇怪的是,我不需要将 fillEnabled 设置为 true,也可以使用它。

setFillBefore() / android:fillBefore

似乎在代码和 XML 中都没有效果/被忽略

setFillEnabled() / android:fillEnabled

似乎在代码和 XML 中都没有影响/被忽略。即使不包括 fillEnabled 或将 fillEnabled 设置为 false,我仍然可以让 fillAfter 工作。

setStartOffset() / android:startOffset

这仅适用于代码,不适用于 XML。

【讨论】:

    【解决方案2】:

    我发现 标记在 AnimationSet 类中的实现存在错误。
    它无法正确处理 repeatCount
    我们能做的就是直接在 标签中设置 repeatCount

    此 XML 资源运行良好:

    <?xml version="1.0" encoding="utf-8"?>
    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:duration="200"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:toXScale="1.05"
        android:toYScale="1.05"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatMode="reverse"
        android:fillAfter="false"
        android:repeatCount="24"
    />
    

    很遗憾,这一次只能播放一个动画。
    我们不能以这种方式定义动画序列...

    【讨论】:

    • 我在一组中运行 2 个动画,它们没有给我任何问题。请告诉我你在说哪个问题?哪个错误?目前正在开发 1.6 sdk
    • 在 xml 中声明 repeatCount 有效,但在代码中无效
    【解决方案3】:

    你应该包含属性

    android:repeatCount="infinite"
    

    但是在你的“缩放”动画中不是在“设置”中

    【讨论】:

    • 但是这些动画会等待前面的动画完成吗?谢谢
    • 谢谢,这成功了!无论出于何种原因,以编程方式设置它都没有。
    • 谢谢!这行得通。但它是连续的。是否有可能每 5 秒发生一次?
    【解决方案4】:

    为了获得重复的动画,我使用了动画监听器,并在动画结束时再次调用动画。这会像带括号的动画一样聚焦相机标线。

    这里是动画布局xml

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:fromXScale="1.0"
        android:toXScale=".7"
        android:fromYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toYScale=".7"
        android:duration="1000"/>
    <scale 
        android:duration="1000"
        android:fromXScale=".7"
        android:toXScale="1.0"
        android:fromYScale=".7"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toYScale="1.0"
        android:startOffset="1000"/>
    
    </set>
    

    这里是java代码

     public void startAnimation() {
    
                View brackets = findViewById(R.id.brackets);
                brackets.setVisibility(View.VISIBLE);
    
                Animation anim = AnimationUtils.loadAnimation(BuzzFinderActivity.this, R.anim.crosshair_focusing);
                anim.setAnimationListener(new AnimationListener() {
    
                    @Override
                    public void onAnimationEnd(Animation arg0) {
                        Animation anim = AnimationUtils.loadAnimation(BuzzFinderActivity.this, R.anim.crosshair_focusing);
                        anim.setAnimationListener(this);
                        brackets.startAnimation(anim);
    
                    }
    
                    @Override
                    public void onAnimationRepeat(Animation arg0) {
                        // TODO Auto-generated method stub
    
                    }
    
                    @Override
                    public void onAnimationStart(Animation arg0) {
                        // TODO Auto-generated method stub
    
                    }
    
                });
    
    
                brackets.startAnimation(anim);
    }
    

    【讨论】:

    • 是的,它应该是正确的答案。在所有设备和操作系统级别工作
    • 它也对我有帮助,但我从 End 方法 Animation anim = AnimationUtils.loadAnimation(BuzzFinderActivity.this, R.anim.crosshair_focusing) 中删除了这两行anim.setAnimationListener(this);
    【解决方案5】:

    我也遇到了同样的问题.. 我在 XMl 文件中包含了 android:repeatCount="infinite" ..现在它工作正常...

      <translate 
               android:fromXDelta="0"
               android:toXDelta="80"
               android:duration="1000"
               android:repeatCount="infinite"   
               android:repeatMode="reverse" 
               android:pivotX="50%"
               android:pivotY="50%"                             
               android:fillAfter="true"/>
    

    【讨论】:

      【解决方案6】:

      你可以试试这个代码。 只需在您的代码中添加,

      firstAnimation.setRepeatCount(5);
      

      这将在一定时间内重复动画

      firstAnimation.setRepeatCount(Animation.INFINITE);
      firstAnimation.setRepeatMode(Animation.INFINITE);
      

      这将无限期地重复动画。

      【讨论】:

      【解决方案7】:

      我尝试使用 Daniel 的代码来显示动画的确切次数,但遇到了一个问题:动画大约显示了 n / 2 次,而预期是 n 次。

      所以我修改了丹尼尔的代码:

      //...
      @Override
      public void onAnimationEnd(Animation arg0) {
          mCurrentCount++;
          if (mCurrentCount < REPEAT_COUNT) {  
              Animation anim = AnimationUtils.loadAnimation(BuzzFinderActivity.this, R.anim.crosshair_focusing);
              anim.setAnimationListener(this);
              brackets.post(new Runnable() {
                  @Override
                  public void run() {
                      brackets.startAnimation(anim);
                  }
              }  
          } 
      }
      //... 
      

      使用变体,如上所示,动画会显示 REPEAT_COUNT 次,因为 View.post() 方法提供了在完成所有动作后开始新动画的能力,与之前的动画相关。

      【讨论】:

        【解决方案8】:

        您只需在我在下面建议的 xml 代码中添加一行。

        <scale
            android:duration="500"
            android:fromXScale="1.0"
            android:fromYScale="1.0"
            android:toXScale="1.2"
            android:toYScale="1.2"
            android:pivotX="50%"
            android:pivotY="50%"
            android:repeatCount="infinite" // just add this one line 
            android:fillAfter="false"
            />
        </set>
        

        【讨论】:

          【解决方案9】:

          我之前在我的项目中使用android:repeatMode="reverse" 解决了这个问题。

          <scale
              android:interpolator="@android:anim/decelerate_interpolator"
              android:duration="500"
              android:fromXScale="1.0"
              android:fromYScale="1.0"
              android:toXScale="1.2"
              android:toYScale="1.2"
              android:pivotX="50%"
              android:pivotY="50%"
              android:repeatMode="reverse"
              android:repeatCount="infinite" />
          

          【讨论】:

            【解决方案10】:

            使用 android sdk 版本 4.0.3:

            在给定的动画元素中:

            android:repeatCount="-1"

            使其成为无限动画。

            【讨论】:

            • 谢谢!它在 4.2 上工作正常,没有任何解决方法
            【解决方案11】:

            将以下类添加到您的项目中:

            import android.view.View;
            import android.view.animation.Animation;
            
            public class AnimationRepeater implements Animation.AnimationListener
            {
                private View view;
                private Animation animation;
                private int count;
            
                public AnimationRepeater(View view, Animation animation)
                {
                    this.view = view;
                    this.animation = animation;
                    this.count = -1;
                }
            
                public AnimationRepeater(View view, Animation animation, int count)
                {
                    this.view = view;
                    this.animation = animation;
                    this.count = count;
                }
            
                public void start()
                {
                    this.view.startAnimation(this.animation);
                    this.animation.setAnimationListener(this);
                }
            
                @Override
                public void onAnimationStart(Animation animation) { }
            
                @Override
                public void onAnimationEnd(Animation animation)
                {
                    if (this.count == -1)
                        this.view.startAnimation(animation);
                    else
                    {
                        if (count - 1 >= 0)
                        {
                            this.animation.start();
                            count --;
                        }
                    }
                }
            
                @Override
                public void onAnimationRepeat(Animation animation) { }
            }
            

            对于视图的无限循环,请执行以下操作:

            Animation a = AnimationUtils(Context, R.anim.animation);
            new AnimationRepeater(View, a).start();
            

            如果您只想将动画重复 N 次,请执行以下操作:

            Animation a = AnimationUtils(Context, R.anim.animation);
            new AnimationRepeater(View, a, int N).start();
            

            N代表重复次数。

            【讨论】:

              【解决方案12】:

              我的大部分工作都是以编程方式完成的,我可能会迟到或效率低下,但这但我完成了重复动画集的目标(我什至有 2 个交替动画集)。所有这些代码所做的只是淡入一个图像,暂停,然后淡出,淡入另一张图像,暂停,淡出,并带回第一个图像(冲洗并重复)。我首先定义了我的 Imageviews:

                  final ImageView purple = (ImageView)findViewById(R.id.purp);
                  final ImageView yellow = (ImageView)findViewById(R.id.yell);
                  purple.setVisibility(View.INVISIBLE);
                  yellow.setVisibility(View.INVISIBLE);
              

              然后我做了两个定时器,任务定时器和处理程序来处理每个动画何时开始和停止:

                  Timer p = new Timer();
                  TimerTask pu = new TimerTask() {
                      public void run() {
                              handler1.post(new Runnable() {
                                      public void run() 
                                      {
                                         fadein(purple);
                                      }
                             });
                      }};
                      p.schedule(pu, 6000, 12000);
              
                  final Handler handler2 = new Handler();
              
                  Timer y = new Timer();
                  TimerTask ye = new TimerTask() {
                      public void run() {
                              handler2.post(new Runnable() {
                                      public void run() 
                                      {
                                         fadein(yellow);
                                      }
                             });
                      }};
              
                      y.schedule(ye, 0, 12000);
              

              最后,我不是通过添加动画来创建动画集,而是通过动画侦听器来确定何时开始每个动画:

              public void fadein (final ImageView image)
              {
                  Animation anim = new AlphaAnimation(0, 1);
              
                  anim.setDuration(2000);
              
                  image.startAnimation(anim);
                  anim.setAnimationListener(new AnimationListener() {
                      public void onAnimationEnd(Animation animation) 
                      {
                          image.clearAnimation();
                          image.invalidate();
                          pause(image);
              
                      }
              
                      @Override
                      public void onAnimationRepeat(Animation animation) {
                          // TODO Auto-generated method stub
              
                      }
              
                      @Override
                      public void onAnimationStart(Animation animation) {
                          // TODO Auto-generated method stub
              
                      }
                  });
              }    
              public void pause (final ImageView image)
              {
                  Animation anim = new AlphaAnimation(1, 1);
              
                  anim.setDuration(2000);
              
                  image.startAnimation(anim);
                  anim.setAnimationListener(new AnimationListener() {
                      public void onAnimationEnd(Animation animation) 
                      {
                          image.clearAnimation();
                          image.invalidate();
                          fadeout(image);
              
                      }
              
                      @Override
                      public void onAnimationRepeat(Animation animation) {
                          // TODO Auto-generated method stub
              
                      }
              
                      @Override
                      public void onAnimationStart(Animation animation) {
                          // TODO Auto-generated method stub
              
                      }
                  });
              }     
              public void fadeout (final ImageView image)
              {
                  Animation anim = new AlphaAnimation(1,0);
              
                  anim.setDuration(2000);
              
                  image.startAnimation(anim);
                  anim.setAnimationListener(new AnimationListener() {
                      public void onAnimationEnd(Animation animation) 
                      {
                          image.clearAnimation();
                          image.invalidate();
                      }
              
                      @Override
                      public void onAnimationRepeat(Animation animation) {
                          // TODO Auto-generated method stub
              
                      }
              
                      @Override
                      public void onAnimationStart(Animation animation) {
                          // TODO Auto-generated method stub
              
                      }
                  });
              }    
              

              clearanimation 和 invalidate 之前的尝试并让这件事正常工作。我不知道他们是否需要。

              希望这对某人有所帮助。


              瑞恩

              【讨论】:

                【解决方案13】:

                我得到了这个去...我试图让视图连续旋转一圈。

                以前我使用的是 rotation.setRepeatMode(-1) ,但这不起作用。切换到 setrepeatcount 并且它可以工作。这是在果冻豆 4.2.2

                 ObjectAnimator rotation = ObjectAnimator.ofFloat(myview,
                                          "rotation", 360).setDuration(2000);
                                rotation.setRepeatMode(-1);
                          rotation.setRepeatCount(Animation.INFINITE); 
                 rotation.start();
                

                【讨论】:

                  【解决方案14】:

                  我也遇到过同样的问题,但我不想在 Java 中做任何计时事情,因为 UI 线程有时可能非常繁忙。 INFINITE 标志不适用于 set 标记。所以我用一小段代码解决了这个问题:

                  mAnimation = (AnimationSet) AnimationUtils.loadAnimation(myContext, R.anim.blink);
                  mIcon.startAnimation(mAnimation);
                  mAnimation.setAnimationListener(new AnimationListener() {
                      public void onAnimationStart(Animation animation) {}
                      public void onAnimationRepeat(Animation animation) {}
                      public void onAnimationEnd(Animation animation) {
                          mIcon.startAnimation(mAnimation);
                      }
                  });
                  

                  使用以下 XML:

                  <alpha
                      xmlns:android="http://schemas.android.com/apk/res/android"
                      android:duration="1000"
                      android:fromAlpha="0.0"
                      android:toAlpha="1.0" />
                  
                  <alpha
                      xmlns:android="http://schemas.android.com/apk/res/android"
                      android:duration="1000"
                      android:fromAlpha="0.9"
                      android:startOffset="1000"
                      android:toAlpha="0.0" />
                  

                  mIcon 是我布局中的 ImageView。

                  【讨论】:

                    【解决方案15】:

                    我已经解决了这个问题。这是我的修复版本:

                    public class HelloAndroidActivity extends Activity {
                    private static String TAG = "animTest";
                    private Animation scaleAnimation;
                    private int currentCover = 0;
                    private List<ImageView> imageViews = new ArrayList<ImageView>(3);
                    private Button btn;
                    private ImageView img;
                    
                    /**
                     * Called when the activity is first created.
                     * @param savedInstanceState If the activity is being re-initialized after 
                     * previously being shut down then this Bundle contains the data it most 
                     * recently supplied in onSaveInstanceState(Bundle). <b>Note: Otherwise it is null.</b>
                     */
                    @Override
                    public void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        Log.i(TAG, "onCreate");
                        setContentView(R.layout.test);
                    
                        img = (ImageView)findViewById(R.id.testpict);
                        imageViews.add(img);
                        img = (ImageView)findViewById(R.id.testpictTwo);
                        imageViews.add(img);
                        img = (ImageView)findViewById(R.id.testpict3);
                        imageViews.add(img);
                    
                        scaleAnimation = AnimationUtils.loadAnimation(this, R.anim.photo_scale);
                        scaleAnimation.setAnimationListener(new CyclicAnimationListener());
                    
                        btn = (Button)findViewById(R.id.startBtn);
                        btn.setOnClickListener(new View.OnClickListener() {
                    
                            @Override
                            public void onClick(View v) {
                                imageViews.get(0).startAnimation(scaleAnimation);
                            }
                        });
                    
                    
                    
                    }
                    
                    private class CyclicAnimationListener implements AnimationListener{
                    
                        @Override
                        public void onAnimationEnd(Animation animation) {
                            currentCover += 1;
                            if(currentCover >= imageViews.size()){
                                currentCover = 0;
                            }
                            img = imageViews.get(currentCover);
                            scaleAnimation = AnimationUtils.loadAnimation(HelloAndroidActivity.this, R.anim.photo_scale);
                            scaleAnimation.setAnimationListener(new CyclicAnimationListener());
                            img.startAnimation(scaleAnimation);
                        }
                    
                        @Override
                        public void onAnimationRepeat(Animation animation) {
                            Log.d("Animation", "Repeat");
                        }
                    
                        @Override
                        public void onAnimationStart(Animation animation) {
                    
                        }
                    
                    }
                    
                    }
                    

                    【讨论】:

                      【解决方案16】:

                      我在开发向后兼容的应用程序时遇到了这个问题。太令人沮丧了!我最终编写了一个很好的解决方法类,可以从 onCreate 调用,并将任何动画资源启动到无限循环中。

                      AnimationLooper 类在此处可用: https://gist.github.com/2018678

                      【讨论】:

                        【解决方案17】:

                        通过互联网上的答案进行研究后,我找到了一个非常适合我的解决方案。 (是的,repeatCount 和 repeatMode 与 animationSet 一起使用时非常有问题)。

                        anim_rotate_fade.xml:

                        <?xml version="1.0" encoding="utf-8"?>
                        <set xmlns:android="http://schemas.android.com/apk/res/android"
                            android:interpolator="@android:anim/accelerate_decelerate_interpolator"
                            android:ordering="together" >
                        
                            <objectAnimator
                                android:duration="3000"
                                android:propertyName="rotation"
                                android:repeatCount="1"
                                android:valueTo="360"
                                android:valueType="floatType" />
                        
                            <objectAnimator
                                android:duration="3000"
                                android:propertyName="alpha"
                                android:repeatCount="1"
                                android:repeatMode="reverse"
                                android:valueFrom="0.0"
                                android:valueTo="0.3"
                                android:valueType="floatType" />
                        
                            <objectAnimator
                                android:duration="3000"
                                android:propertyName="y"
                                android:repeatCount="1"
                                android:repeatMode="reverse"
                                android:valueFrom="380"
                                android:valueTo="430"
                                android:valueType="floatType" />
                        
                        </set>
                        

                        活动中: (通过在动画结束后引入一点延迟来解决)。

                        ImageView starlightImageView = new ImageView(this);
                        starlightImageView.setImageResource(R.drawable.starlight);
                        final AnimatorSet animate = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.anim.anim_rotate_fade);
                        AnimatorListenerAdapter animatorListener = new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator animation) {
                                super.onAnimationEnd(animation);
                                new Handler().postDelayed(new Runnable() {
                                    @Override public void run() {
                                        animate.start();
                                    }
                                }, 1000);
                            }
                        };
                        animate.setTarget(starlightImageView);
                        animate.addListener(animatorListener);
                        

                        您想研究很多类,但目前我使用的是高度灵活的 objectAnimator。我不建议使用 Animation 或 AnimationUtils:

                        • 动画
                        • AnimationUtils
                        • 动画师
                        • AnimatorInflater
                        • AnimatorListener
                        • AnimatorListenerAdapter

                        【讨论】:

                          【解决方案18】:

                          需要监听第一个动画的完成,然后在 onStopAnimation 回调中重新启动动画,试试这个link

                          【讨论】:

                            【解决方案19】:

                            对@Danufr 的回答稍作调整,以节省资源再次加载。

                                operator = (ImageView) findViewById(R.id.operator_loading);
                              final  Animation ani = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.finding_operator);
                            
                            
                                ani.setAnimationListener(new Animation.AnimationListener() {
                                    @Override
                                    public void onAnimationStart(Animation animation) {
                            
                                    }
                            
                                    @Override
                                    public void onAnimationEnd(Animation animation) {
                            
                                        operator.startAnimation(ani);
                            
                                    }
                            
                                    @Override
                                    public void onAnimationRepeat(Animation animation) {
                            
                                    }
                                });
                            
                                operator.setAnimation(ani);
                            

                            【讨论】:

                              【解决方案20】:

                              我使用线程解决了这个问题。

                              Button btn = (Button) findViewById(R.id.buttonpush);
                                  final TextView textview = (TextView) findViewById(R.id.hello);
                                  btn.setOnClickListener(new View.OnClickListener() {
                                      @Override
                                      public void onClick(View view) {
                                          textview.setText("...................");
                                          final Animation animationtest = AnimationUtils.loadAnimation(MainActivity.this, android.R.anim.slide_in_left);
                                          animationtest.setDuration(1000);
                              
                                          final Handler handler = new Handler();
                                          Runnable runnable = new Runnable() {
                                              public void run() {
                                                  handler.postDelayed(this, 1500);
                                                  textview.startAnimation(animationtest);
                                              }
                                          };
                                          handler.postDelayed(runnable, 500); // start
                                          handler.removeCallbacks(runnable); //STOP Timer
                              
                                      }
                                  });
                              

                              【讨论】:

                                【解决方案21】:

                                一切正常

                                 GifDrawable gifDrawable = (GifDrawable) gifImageView.getDrawable();
                                    gifDrawable.setLoopCount(0);
                                

                                【讨论】:

                                  【解决方案22】:

                                  以上解决方案均不适用于我的情况。 Danuofr 的解决方案确实适用于动画集,但是当我进行单元测试时,我的测试常常陷入这个无限循环。最后,根据我的情况,我需要重复这个动画特定的次数。因此,我以级联方式在 anim_rot.xml 中手动添加了我的动画副本添加偏移值。我知道这很糟糕,对很多人都不起作用,但这是我的情况的唯一解决方法。

                                  anim_rot.xml

                                  <set xmlns:android="http://schemas.android.com/apk/res/android">
                                      <rotate
                                          android:duration="2000"
                                          android:fromDegrees="20"
                                          android:pivotX="29%"
                                          android:pivotY="50%"
                                          android:toDegrees="-20" />
                                      <rotate
                                          android:duration="2000"
                                          android:fromDegrees="-20"
                                          android:pivotX="29%"
                                          android:pivotY="53%"
                                          android:startOffset="2000"
                                          android:toDegrees="20" />
                                      <rotate
                                          android:startOffset="4000"
                                          android:duration="2000"
                                          android:fromDegrees="20"
                                          android:pivotX="29%"
                                          android:pivotY="56%"
                                          android:toDegrees="-20" />
                                      <rotate
                                          android:duration="2000"
                                          android:fromDegrees="-20"
                                          android:pivotX="29%"
                                          android:pivotY="59%"
                                          android:startOffset="6000"
                                          android:toDegrees="20" />
                                      <rotate
                                          android:startOffset="8000"
                                          android:duration="2000"
                                          android:fromDegrees="20"
                                          android:pivotX="29%"
                                          android:pivotY="62%"
                                          android:toDegrees="-20" />
                                      <rotate
                                          android:duration="2000"
                                          android:fromDegrees="-20"
                                          android:pivotX="29%"
                                          android:pivotY="65%"
                                          android:startOffset="10000"
                                          android:toDegrees="20" />
                                  </set>
                                  

                                  我这样做是为了重复动画 3 次。您可以通过添加偏移值来添加更多副本以重复特定时间。

                                  【讨论】:

                                    【解决方案23】:

                                    尝试将代码添加到循环线程或 while/for 语句中

                                    【讨论】:

                                    • 嗯,我发现的唯一解决方案是避免使用 set 标签。
                                    猜你喜欢
                                    • 1970-01-01
                                    • 1970-01-01
                                    • 1970-01-01
                                    • 1970-01-01
                                    • 1970-01-01
                                    • 2012-07-19
                                    • 1970-01-01
                                    • 2016-03-29
                                    • 1970-01-01
                                    相关资源
                                    最近更新 更多