import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView tv_hello_world;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void tiaozhuan(View view) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
//淡入 淡出 的动画效果
// overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
//从左向右 的滑动效果
overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
}
}
对应退出时设置
package com.wust.myanimation;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
/**
-
ClassName: SecondActivity
-
Description:
-
date: 2021/7/18 12:43
-
@author yiqi
-
@QQ 1820762465
-
@微信 yiqiideallife
-
@技术交流QQ群 928023749
*/
public class SecondActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
@Override
public void finish() {
super.finish();
//淡入 淡出 的动画效果
overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
//从左向右 的滑动效果
// overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
}
}
效果展示
利用自定义动画设置
第一步:在 res/anim/ 文件夹下分别创建 enter.xml 和 exit.xml 文件
// enter.xml
<?xml version="1.0" encoding="utf-8"?><scale android:pivotX=“0%p”
android:pivotY=“0%p”
android:fromXScale=“0%p”
android:toXScale=“100%p”
android:fromYScale=“0%p”
android:toYScale=“100%p”/>
//exit.xml
<?xml version="1.0" encoding="utf-8"?><scale android:pivotX=“0%p”
android:pivotY=“0%p”
android:fromXScale=“100%p”
android:toXScale=“0%p”
android:fromYScale=“100%p”
android:toYScale=“0%p”/>
第二步:和使用系统动画一样 用起来就好了
启动时的设置
package com.wust.myanimation;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.BounceInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private Text
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
View tv_hello_world;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void tiaozhuan(View view) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter,R.anim.exit);
}
}
退出时的设置
package com.wust.myanimation;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
/**
- ClassName: SecondActivity