Kon*_*pko 0 android android-animation
我想要第一个我的布局放大,第二个它应该通过反弹缩小。但是这段代码不能正常工作。
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially" >
<set>
<scale
android:duration="400"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.2"
android:toYScale="1.2" />
</set>
<set android:interpolator="@android:anim/bounce_interpolator" >
<scale
android:duration="800"
android:fromXScale="1.2"
android:fromYScale="1.2"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" />
</set></set>
Run Code Online (Sandbox Code Playgroud)
我对对象动画师了解不多,但我使用属性动画进行了多次缩放,效果很好!这是代码
AnimatorSet set = new AnimatorSet(); //this is your animation set.
//add as many Value animator to it as you like
ValueAnimator scaleUp = ValueAnimator.ofFloat(1,(float)1.2);
scaleUp.setDuration(800);
scaleUp.setInterpolator(new BounceInterpolator()); //remove this if you prefer default interpolator
scaleUp.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
Float newValue = (Float) valueAnimator.getAnimatedValue();
yourView.setScaleY(newValue);
yourView.setScaleX(newValue);
}
});
ValueAnimator scaleDown = ValueAnimator.ofFloat((float)1.2,1);
scaleDown.setDuration(800);
scaleDown.setInterpolator(new BounceInterpolator());
scaleDown.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
Float newValue = (Float) valueAnimator.getAnimatedValue();
yourView.setScaleY(newValue);
yourView.setScaleX(newValue);
}
});
set.play(saceleUp);
set.play(scaleDown).after(scaleUP);
set.start();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2990 次 |
| 最近记录: |