android动画跳转

ImageView iv = (ImageView) findViewById(R.id.iv);
        //测量屏幕
        DisplayMetrics displayMetrics = this.getResources().getDisplayMetrics();
        int heightPixels = displayMetrics.heightPixels/2+iv.getHeight();
        //移动屏幕高度的一半
        ObjectAnimator translationY = ObjectAnimator.ofFloat(iv, "translationY", 0, heightPixels);
        //缩放
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(iv, "scaleX", 2f, 1f);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(iv, "scaleY", 2f, 1f);
        //渐变
        ObjectAnimator alpha = ObjectAnimator.ofFloat(iv, "alpha", 0, 1f);
        //旋转
        ObjectAnimator rotation = ObjectAnimator.ofFloat(iv, "rotation", 0, 360);
        //动画集合
        AnimatorSet animatorSet = new AnimatorSet();
        //把动画放在一起
        animatorSet.playTogether(translationY,scaleX,scaleY,alpha,rotation);
        animatorSet.setDuration(3000);
        animatorSet.start();
        //当动画结束时跳转页面
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                startActivity(new Intent(SplashActivity.this,MainActivity.class));
                //---------------页面缓冲
                overridePendingTransition(R.anim.enter,R.anim.out);
            }
        });
在src目录下创建anim文件夹,创建'新页面从右进入','旧页面从左出去'的动画
<?xml version="1.0" encoding="utf-8"?>
<!--新页面进入的动画,X轴从100%到达0%设置1s的动画时长-->
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="100%"
    android:toXDelta="0%"
    android:duration="1000">

</translate>
<?xml version="1.0" encoding="utf-8"?>
<!--旧页面出去的动画,X轴从0%到达-100%设置1s的动画时长-->
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromXDelta="0%"
    android:toXDelta="-100%">

</translate>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值