2015-11-04 30 views
0

我想縮放圖像,旋轉它,向後旋轉,然後將其縮放到原始大小。 這是allready工作,但我無法弄清楚如何重複這個動畫設置無限(android:repeatCount="infinite"不是爲我工作)。Android動畫重複 - >圖像動畫設置

<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
android:shareInterpolator="true" 
android:repeatCount="infinite" 
> 
<scale 
    android:fromXScale="1.0" 
    android:toXScale="4.0" 
    android:fromYScale="1.0" 
    android:toYScale="4.0" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:duration="700" 
    /> 
<rotate 
    android:fromDegrees="0" 
    android:toDegrees="360" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:startOffset="700" 
    android:duration="2000" 
    /> 
<rotate 
    android:fromDegrees="360" 
    android:toDegrees="0" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:startOffset="2700" 
    android:duration="2000" 

    /> 

<scale 
    android:fromXScale="1.0" 
    android:toXScale="0.25" 
    android:fromYScale="1.0" 
    android:toYScale="0.25" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:startOffset="4700" 
    android:duration="700" 
    /> 
</set> 

,並在活動:在XML

ImageView imageView = (ImageView) findViewById(R.id.imageView2); 
Animation rotateAndScale = AnimationUtils.loadAnimation(this, R.anim.rotate_z); 
imageView.startAnimation(rotateAndScale); 

回答

1

<set>標記壞的實施,而不是propperly工作。這裏完整的補充:Android animation does not repeat

你應該做的就是使用監聽器和方法來使用recurency來滾動anim。

public void startAnimation() { 

     View component= findViewById(R.id.imageView2); 
     component.setVisibility(View.VISIBLE); 

     Animation anim = AnimationUtils.loadAnimation(this, R.anim.rotate_z); 
     anim.setAnimationListener(new AnimationListener() { 

      @Override 
      public void onAnimationEnd(Animation arg0) { 
       Animation anim = AnimationUtils.loadAnimation(this, R.anim.rotate_z); 
       anim.setAnimationListener(this); 
       component.startAnimation(anim); 

      } 

      @Override 
      public void onAnimationRepeat(Animation arg0) { 
       // TODO Auto-generated method stub 

      } 

      @Override 
      public void onAnimationStart(Animation arg0) { 
       // TODO Auto-generated method stub 

      } 

     }); 

     component.startAnimation(anim); 

}