当使用动画时,我可以做这样的事情
ScaleAnimation animation = new ScaleAnimation(0, 1.0, 0, 1.0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
从 0 缩放到对象的原始大小。
我如何用 ObjectAnimator
或 ValueAnimator
做同样的事情?
最佳答案
你可以为 ValueAnimator 使用这样的东西:
ValueAnimator translate = ValueAnimator.ofFloat(1f, 1.5f);
translate.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float scale = Float.parseFloat(animation.getAnimatedValue().toString());
yourView.setScaleX(scale);
yourView.setScaleY(scale);
}
});
translate.start();
ObjectAnimator 类似这样的东西:
AnimatorSet animationSet = new AnimatorSet();
ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 1.5f);
ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 1.5f);
animationSet.playTogether(scaleX, scaleY);
animationSet.start();
您还可以为两个动画设置持续时间/插值器/延迟和类似属性。也不要忘记在配置后启动动画。
注意: 没有测试这段代码,有些东西可能无法正常工作。
关于android - 如何使用 Object Animator 制作放大动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50829140/