android 动画animation setRepeatCount不起作用

来源:互联网 发布:大学生防网络诈骗 编辑:程序博客网 时间:2024/06/07 02:26

以 xml的形式定义了动画,但是没有起作用

如下:

[html] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:duration="1500"  
  4.     android:repeatMode="restart"  
  5.     android:repeatCount="-1">  
  6.     <scale  
  7.         android:fromXScale="1"  
  8.         android:fromYScale="1"  
  9.         android:pivotX="50%"  
  10.         android:pivotY="50%"  
  11.         android:toXScale="1.5"  
  12.         android:toYScale="1.5"></scale>  
  13. </set>  

解决方法:

把重复播放的 配置 放在对应的 动画效果节点下

[html] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:duration="1500">  
  4.     <scale  
  5.         android:fromXScale="1"  
  6.         android:fromYScale="1"  
  7.         android:pivotX="50%"  
  8.         android:pivotY="50%"  
  9.         android:repeatCount="-1"  
  10.         android:repeatMode="restart"  
  11.         android:toXScale="1.5"  
  12.         android:toYScale="1.5"></scale>  
  13. </set>  

如果 同时在代码中 设置了 动画重复配置,起作用的是 xml形式的动画配置

原因如下:

Animation 源码中

[html] view plain copy
  1. public Animation(Context context, AttributeSet attrs) {  
  2.        TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Animation);  
  3.        .....  
  4.        setRepeatCount(a.getInt(com.android.internal.R.styleable.Animation_repeatCount, mRepeatCount));  
  5.        setRepeatMode(a.getInt(com.android.internal.R.styleable.Animation_repeatMode, RESTART));  
  6.        ....  
  7.    }