我试图在进入和退出活动时添加滑动动画,但它仅在按下手机后退按钮时才有效。当按下工具栏中的向上按钮或单独的按钮时,它不起作用。
我尝试将overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
行添加到onPause()
方法以及finish()
方法和按钮 OnClick 方法,但它不起作用:/
no_anim.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="0"
android:fromXDelta="0"
android:toXDelta="0" />
</set>
slide_out_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="0"
android:toXDelta="100%p" />
</set>
爪哇:
public void button(View view) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}
@Override
public void finish(){
super.finish();
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}
@Override
protected void onPause() {
super.onPause();
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}