首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >创作简单动画

创作简单动画
EN

Stack Overflow用户
提问于 2015-03-09 15:18:43
回答 2查看 205关注 0票数 0

我需要您的帮助,以了解如何管理由Android中的一些简单动画构建的复杂动画:我有这个动画xml文件:

代码语言:javascript
运行
复制
<?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等等.

我怎样才能达到我的目标?我的问题有两个:首先,规模动画顺序没有遵循(似乎所有动画都是一起开始的)。然后,我怎样才能永远重复所有的序列呢?谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-03-09 17:12:36

我遇到了一个类似的问题。最好的做法是用代码(而不是XML )来做事情。因此,您为每个动画设置一个动画监听器,并且在AnimationEnd上控制您是要重复还是启动下一个动画。

票数 1
EN

Stack Overflow用户

发布于 2015-03-09 16:03:45

您可以使用"startOffset“启动延迟的动画:

代码语言:javascript
运行
复制
<?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,所以必须以编程方式重复动画。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28945562

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档