我需要您的帮助,以了解如何管理由Android中的一些简单动画构建的复杂动画:我有这个动画xml文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- A: executed only one time at the beginning -->
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.2"
android:toYScale="0.2" />
<!-- B: executed only one time AFTER A -->
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXScale="0.2"
android:fromYScale="0.2"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1"
android:toYScale="1" />
<!-- C: Executed 5 times after B -->
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="5"
android:repeatMode="reverse"
android:toXScale="0.8"
android:toYScale="0.8" />
<!-- AT THE END REPEAT ALL FROM THE A TO C -->
</set>我在文件中放置了一些简单的缩放动画,正如您可以从注释中看到的那样,我想创建以下(无限)序列:
A-B-C等等.
我怎样才能达到我的目标?我的问题有两个:首先,规模动画顺序没有遵循(似乎所有动画都是一起开始的)。然后,我怎样才能永远重复所有的序列呢?谢谢。
发布于 2015-03-09 17:12:36
我遇到了一个类似的问题。最好的做法是用代码(而不是XML )来做事情。因此,您为每个动画设置一个动画监听器,并且在AnimationEnd上控制您是要重复还是启动下一个动画。
发布于 2015-03-09 16:03:45
您可以使用"startOffset“启动延迟的动画:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- A: executed only one time at the beginning -->
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.2"
android:toYScale="0.2" />
<!-- B: executed only one time AFTER A -->
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:startOffset="3000"
android:duration="300"
android:fromXScale="0.2"
android:fromYScale="0.2"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1"
android:toYScale="1" />
<!-- C: Executed 5 times after B -->
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:startOffset="3300"
android:duration="300"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="5"
android:repeatMode="reverse"
android:toXScale="0.8"
android:toYScale="0.8" />
<!-- AT THE END REPEAT ALL FROM THE A TO C -->
</set>由于不能在动画集上设置repeatCount,所以必须以编程方式重复动画。
https://stackoverflow.com/questions/28945562
复制相似问题