0

这些是我在 xml 中设置的动画器,我想转换为 java 代码,但我不知道如何在“AnimatorSet”中设置“AnimatorSet”?

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially">
    <set>
        <objectAnimator
            android:duration="50"
            android:propertyName="scaleX"
            android:valueFrom="1.0"
            android:valueTo="0.8" />
        <objectAnimator
            android:duration="50"
            android:propertyName="scaleY"
            android:valueFrom="1.0"
            android:valueTo="0.8" />
    </set>

    <set>
        <objectAnimator
            android:duration="50"
            android:propertyName="scaleX"
            android:valueFrom="0.8"
            android:valueTo="1.1" />
        <objectAnimator
            android:duration="50"
            android:propertyName="scaleY"
            android:valueFrom="0.8"
            android:valueTo="1.1" />
    </set>
</set>
4

1 回答 1

0

首先你要创建一个AnimatorSet来一起播放动画,然后在AnimatorSet中添加两个ObjectAnimator,像这样:

AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
            ObjectAnimator.ofFloat(view, "scaleX", 1, 0.8f, 1.1f),
            ObjectAnimator.ofFloat(view, "scaleY", 1, 0.8f, 1.1f)
    );
animatorSet.setDuration(1000);
animatorSet.start();    
于 2016-12-27T14:48:20.443 回答