AnimatorSet将图片放大5倍再复原接着图片垂直下移到底部再复位执行完后页面跳转到下一个页面
你可以使用以下代码来实现AnimatorSet的效果:
// 创建一个ImageView对象并设置初始属性
ImageView imageView = findViewById(R.id.imageView);
imageView.setScaleX(1.0f);
imageView.setScaleY(1.0f);
// 创建一个AnimatorSet对象
AnimatorSet animatorSet = new AnimatorSet();
// 创建一个放大图片的动画
ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(imageView, "scaleX", 5.0f);
ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(imageView, "scaleY", 5.0f);
scaleXAnimator.setDuration(1000);
scaleYAnimator.setDuration(1000);
// 创建一个垂直移动图片的动画
ObjectAnimator translationYAnimator = ObjectAnimator.ofFloat(imageView, "translationY", 0, imageView.getHeight());
translationYAnimator.setDuration(1000);
// 创建一个复位图片的动画
ObjectAnimator resetScaleXAnimator = ObjectAnimator.ofFloat(imageView, "scaleX", 1.0f);
ObjectAnimator resetScaleYAnimator = ObjectAnimator.ofFloat(imageView, "scaleY", 1.0f);
resetScaleXAnimator.setDuration(1000);
resetScaleYAnimator.setDuration(1000);
// 设置动画的先后顺序和依赖关系
animatorSet.play(scaleXAnimator).with(scaleYAnimator).before(translationYAnimator).before(resetScaleXAnimator).before(resetScaleYAnimator);
// 设置动画执行完后跳转到下一个页面
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
// 跳转到下一个页面的代码
}
});
// 启动动画
animatorSet.start();
这里假设你有一个ImageView的id为"imageView",你可以根据实际情况修改代码中的id。动画的执行时间可以根据需要进行调整。在动画执行完后,你可以在onAnimationEnd方法中添加页面跳转的代码。
原文地址: https://www.cveoy.top/t/topic/jgTy 著作权归作者所有。请勿转载和采集!