android anmation无法循环播放

来源:互联网 发布:什么是网络市场营销 编辑:程序博客网 时间:2024/04/29 01:56

原创不易,禁止转载,如果非要转载,请注明原文地址http://blog.csdn.net/z736232402/article/details/52671053

很多时候会用到简单动画,例如,loading的那个转圈的,于是网上随便copy了下动画代码。
f_roate_loading.xml

 <?xml version="1.0" encoding="utf-8"?><set    xmlns:android=""    android:duration="1000"    android:repeatMode="reverse"    >    <rotate        android:fromDegrees="0"        android:pivotX="50%"        android:pivotY="50%"        android:toDegrees="359"/></set>

代码设置更简单了

Animation animation = AnimationUtils.loadAnimation(context, R.anim.f_roate_loading);animation .setRepeatCount(Animation.INFINITE);mView.startAnimation(animation)

然后就发现,为啥自己的动画只能执行一次呢?怪来怪去的,最后也没怪对地方,后来和同学探讨的时候,看了下他的代码,发现他的动画代码的是

<?xml version="1.0" encoding="utf-8"?><rotate    xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="1000"    android:fromDegrees="0"    android:pivotX="50%"    android:pivotY="50%"    android:repeatMode="restart"    android:toDegrees="359"/>

难道是根标签不能是set?抱着试一试的态度,发现,总算可以一直转了。
分析下原因,先看下官方的文档吧

setRepeatCount() / android:repeatCount

This attribute (as well as repeatMode) does not work in code or XML. This makes repeating an entire set of animations difficult.

官网就是不允许set动画设置重复,对于需要动画集重复的,只能另外想办法了。

0 0