HarmonyOS 动画中 AnimatorProperty setLoopedCount(int loopedCount)

 Android 实现代码:

    public static void animAlphaScaleShowView(final View view, int time_ms) {
        if (animFlag) return;
        AnimationSet set = new AnimationSet(true);
        AlphaAnimation alphaAnim = new AlphaAnimation(0.2f, 1.0f);
        set.addAnimation(alphaAnim);

        ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 1.5f, 1.0f, 1.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        set.addAnimation(scaleAnim);
        set.setFillAfter(true);
        set.setDuration(time_ms);

        set.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                animFlag = true;
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                animFlag = false;
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        view.startAnimation(set);
    }

鸿蒙实现代码:

    public static void animAlphaScaleShowView(final Component view, int time_ms) {
        AnimatorProperty animator = view.createAnimatorProperty();
        //
        view.setAlpha(0.2f);
        animator.alpha(1.0f);
        //
        animator.setCurveType(Animator.CurveType.ANTICIPATE_OVERSHOOT);
        animator.scaleXFrom(1.0f);
        animator.scaleX(1.5f);
        animator.scaleYFrom(1.0f);
        animator.scaleY(1.5f);
        //
        animator.setDuration(time_ms);
        //
        animator.setLoopedCount(0);
        animator.start();
    }

 对比两者有什么区别,都是透明度+缩放的变化   我感觉Android提供构造函数稍微好一点。不过4.0都不用java了 也无所谓了。

但是其中 setLoopedCount()  让我确实没摸着头脑,看见这个参数是不是首先认为 要么是不限循环、要么是播放几次,为什么播放是次数是从0开始 。实际上传0 会播放一次、1播放2次,这个API 这个参数一点都不友好。

看官方的解释:

setLoopedCount

public AnimatorProperty setLoopedCount​(int loopedCount)

Sets the repetition times of an animator.

Parameters:

Parameter Name

Parameter Description

loopedCount

Specifies the repetition times of an animator. The value must be greater than or equal to 0, or INFINITE. If the value is 0, the animator will be played only once.

Returns:

Returns the current property animator for continuous property settings.

 确实count是从0开始的,所以还是在开发中要注意一下。

https://developer.harmonyos.com/cn/docs/documentation/doc-references/animatorproperty-0000001054439987#ZH-CN_TOPIC_0000001054439987__setLoopedCount-int-

动画学习参考1:Samples: We provide a series of app samples to help you quickly get familiar with the APIs and app development process of the HarmonyOS SDKs. | 为帮助开发者快速熟悉HarmonyOS SDK所提供的API和应用开发流程,我们提供了一系列的应用示例 - Gitee.com

 动画学习参考2:文档中心

你可能感兴趣的:(harmonyos,华为)