首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何重复属性动画?

如何重复属性动画?
EN

Stack Overflow用户
提问于 2014-08-17 08:02:11
回答 6查看 9.6K关注 0票数 10

我正在做屏幕上的气泡动画,但气泡在动画时间结束后停止。如何重复动画或使其无限大?

代码语言:javascript
复制
bub.animate();
bub.animate().x(x2).y(y2);
bub.animate().setDuration(animationTime);       
bub.animate().setListener(new AnimatorListenerAdapter() {

    @Override
    public void onAnimationStart(Animator animation) {
        animators.add(animation); 
    } 

    @Override
    public void onAnimationRepeat(Animator animation) {
    }

    @Override
    public void onAnimationEnd(Animator animation) {
    }
});
EN

回答 6

Stack Overflow用户

发布于 2014-08-17 08:08:51

因为ViewPropertyAnimator只适用于简单的动画,所以使用更高级的ObjectAnimator类--基本上是setRepeatCount方法,另外还有setRepeatMode

票数 13
EN

Stack Overflow用户

发布于 2016-01-06 22:01:16

这实际上是可能的。以下是旋转视图的示例:

代码语言:javascript
复制
        final ViewPropertyAnimator animator = view.animate().rotation(360).setInterpolator(new LinearInterpolator()).setDuration(1000);

        animator.setListener(new android.animation.Animator.AnimatorListener() {
            ...

            @Override
            public void onAnimationEnd(final android.animation.Animator animation) {
                animation.setListener(null);
                view.setRotation(0);
                view.animate().rotation(360).setInterpolator(new LinearInterpolator()).setDuration(1000).setListener(this).start();
            }

        });

您也可以使用"withEndAction(http://developer.android.com/reference/android/view/ViewPropertyAnimator.html#withEndAction(java.lang.Runnable%29)“而不是侦听器。

票数 7
EN

Stack Overflow用户

发布于 2016-11-03 00:41:50

您可以使用CycleInterpolator。例如,如下所示:

代码语言:javascript
复制
    int durationMs = 60000;
    int cycleDurationMs = 1000;
    view.setAlpha(0f);
    view.animate().alpha(1f)
            .setInterpolator(new CycleInterpolator(durationMs / cycleDurationMs))
            .setDuration(durationMs)
            .start();
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25345129

复制
相关文章

相似问题

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