Android ObjectAnimatorSet XML 转换为 JAVA 代码
Android ObjectAnimatorSet XML Convert To JAVA Code
这些是我在 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>
首先你要创建一个AnimatorSet来一起播放动画,然后添加两个ObjectAnimator到AnimatorSet,像这样:
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();
这些是我在 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>
首先你要创建一个AnimatorSet来一起播放动画,然后添加两个ObjectAnimator到AnimatorSet,像这样:
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();