Android 动画实现图片放大、下移并跳转页面
你可以使用 AnimatorSet 来实现这个动画效果。下面是实现这个动画的代码示例:
// 创建一个 AnimatorSet 对象
AnimatorSet animatorSet = new AnimatorSet();
// 创建一个缩放动画,将图片放大 5 倍
ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(imageView, 'scaleX', 5f);
ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(imageView, 'scaleY', 5f);
// 创建一个垂直移动动画,将图片移动到屏幕底部
ObjectAnimator translationYAnimator = ObjectAnimator.ofFloat(imageView, 'translationY', screenHeight);
// 创建一个复位动画,将图片复位到初始位置
ObjectAnimator resetAnimator = ObjectAnimator.ofFloat(imageView, 'translationY', 0);
// 设置动画的持续时间
scaleXAnimator.setDuration(1000);
scaleYAnimator.setDuration(1000);
translationYAnimator.setDuration(1000);
resetAnimator.setDuration(1000);
// 将动画按顺序添加到 AnimatorSet 中
animatorSet.play(scaleXAnimator).with(scaleYAnimator);
animatorSet.play(translationYAnimator).after(scaleXAnimator);
animatorSet.play(resetAnimator).after(translationYAnimator);
// 设置动画执行完后的页面跳转
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
// 页面跳转代码
Intent intent = new Intent(CurrentActivity.this, NextActivity.class);
startActivity(intent);
}
});
// 启动动画
animatorSet.start();
请注意,上述代码中的 imageView 是你要执行动画的 ImageView 对象,screenHeight 是屏幕的高度。你可以根据实际情况修改这些值。在动画执行完后,将会启动一个新的 Activity 页面。
原文地址: http://www.cveoy.top/t/topic/ca0h 著作权归作者所有。请勿转载和采集!