我正在尝试制作简单的动画,可以重复几次(或无限次)。
看起来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>
首先,它应该在500ms内将图像从1.0缩放到1.2大小。
然后在500毫秒内将其缩减到1.0。
下面是我是如何使用它的:
Animation firstAnimation = AnimationUtils.loadAnimation(this, R.anim.first_animation);
imgView.startAnimation(firstAnimation);
它做一个循环,然后结束。
它先是放大,然后缩小,然后停止。
如何才能使此功能按预期工作?
发布于 2011-06-15 08:45:11
更新:早在2011年9月,一位安卓工程师就解决了这个问题。在XML中被忽略的属性现在可以使用了,除了repeatCount
和fillEnabled
,它们仍然被忽略(出于某种原因)。不幸的是,这意味着仍然不容易重复一次AnimationSet
。
有关详细信息,请参阅updated docs中的概述(解释哪些属性被忽略,哪些属性起作用,以及哪些属性传递给子对象)。要更深入地了解fillAfter
、fillBefore
和fillEnabled
的实际功能,请参阅工程师(Chet Haase)关于它的博客文章here。
原始答案
在Pavel和其他人的回答上进行扩展:<set>
标签确实存在可笑的错误。它不能正确处理repeatCount
和许多其他属性。
我花了几个小时弄清楚它能处理什么,不能处理什么,并在这里提交了一个bug报告/问题:Issue 17662
总之(这与AnimationSet
有关):
setRepeatCount() /android:重复计数
此属性(以及repeatMode)在代码或XML中不起作用。这使得重复整个动画集变得困难。setDuration() /android:在代码中的AnimationSet上设置持续时间有效(重写子动画的所有持续时间),但当包含在XML setFillAfter() /android: for中的标记中时不起作用。奇怪的是,我不需要将fillEnabled设置为true就能让它正常工作。setFillBefore() /android: both在代码和XML中似乎都没有作用/被忽略setFillEnabled() / android:fillEnabled
在代码和XML中似乎都没有影响/被忽略。即使不包含fillEnabled或将fillEnabled设置为false,我仍然可以让fillAfter工作。setStartOffset() /android:开始偏移
这只适用于代码,而不适用于XML.
发布于 2010-12-20 04:25:51
我发现标签在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"
/>
不幸的是,这一次仅限于一个动画。
我们不能以这种方式定义动画序列...
发布于 2011-01-31 01:48:06
您应该包含该属性
android:repeatCount="infinite"
但是在你的“缩放”动画中而不是在“集合”中。
https://stackoverflow.com/questions/4480652
复制相似问题