【问题标题】:Repeat pulse Animation重复脉冲动画
【发布时间】:2015-02-02 18:41:36
【问题描述】:

我正在尝试在 ImageView 中创建无限脉冲效果。 但是怎么可能保持偏移呢?

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
    android:duration="700"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.5"
    android:toYScale="0.5"/>
<scale
    android:duration="700"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:startOffset="700"
    android:toXScale="2"
    android:toYScale="2"/>
</set>

【问题讨论】:

    标签: android loops animation


    【解决方案1】:

    这将使您的 (Image)View 反复跳动到其大小的 1.2 倍。

    ImageView iv = (ImageView) findViewById(R.id.my_imageview);
    
    ObjectAnimator scaleDown = ObjectAnimator.ofPropertyValuesHolder(
                        iv,
                        PropertyValuesHolder.ofFloat("scaleX", 1.2f),
                        PropertyValuesHolder.ofFloat("scaleY", 1.2f));
    scaleDown.setDuration(310);
    
    scaleDown.setRepeatCount(ObjectAnimator.INFINITE);
    scaleDown.setRepeatMode(ObjectAnimator.REVERSE);
    
    scaleDown.start();
    

    【讨论】:

    • 为了让这个动作更自然,我建议添加这样的插值器: scaleDown.setInterpolator(new FastOutSlowInInterpolator());
    • 如何在动画之间暂停?
    • 我试过这个,但这可能会导致它有锯齿状的边缘,使用动画矢量绘图代替它看起来更干净。
    • 我可以用xml制作这个动画吗?
    • 很棒的答案:)
    【解决方案2】:

    您可以为集合中的每个动画设置startOffset 值。

    【讨论】:

      【解决方案3】:

      如果你想创建无限动画,最好的方法是创建自定义视图并在 onDraw 中创建你的动画。例如:How to animate a path on canvas - android

      其实你也可以用 SurfaceView 做动画。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-03
        • 2021-08-30
        • 1970-01-01
        • 2021-08-09
        • 2021-10-18
        • 2015-09-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多