1———动画移入移出

1:在res目录下new出一个来

android动画的淡入淡出加移入移出

anim
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000">
<translate android:fromXDelta="100%" android:toXDelta="0%"></translate>
</set>

2:anim1

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000">
<translate android:fromXDelta="0%" android:toXDelta="-100%"></translate>
</set>

3:MainActivity

private void initAnim() {
    Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.anim);
    imageView.setAnimation(animation);
    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            Intent intent = new Intent(MainActivity.this, Main2Activity.class);

            startActivity(intent);
            overridePendingTransition(R.anim.anim, R.anim.anim1);
            finish();
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
}

2———动画淡入淡出

直接在

MainActivity里面写:

private void initData() {
    AlphaAnimation alphaAnimation = new AlphaAnimation(1f, 0f);
    alphaAnimation.setDuration(3000);
    alphaAnimation.setFillAfter(true);//停止
    main1_img.setAnimation(alphaAnimation);
    alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);
            alphaAnimation.setDuration(3000);
            alphaAnimation.setFillAfter(true);//停止运动轨迹
            main1_img.setAnimation(alphaAnimation);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    new CountDownTimer(6000, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {

        }

        @Override
        public void onFinish() {
            startActivity(new Intent(MainActivity.this, Main2Activity.class));
        }
    }.start();
}

相关文章: