slide out animation not working on back press button?
I used slide_in.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="100%"
android:toXDelta="0%" >
</translate>
slide_out.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="0%"
android:toXDelta="-100%" >
</translate>
slide_enter.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="-100%"
android:toXDelta="0%" >
</translate>
slide_exit.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="0%"
android:toXDelta="100%" >
</translate>
Code
Intent i=new Intent(Authentication.this,Login.class);
startActivity(i);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
To previous
finish();
overridePendingTransition(R.anim.slide_enter, R.anim.slide_exit);
Add animation in onBackPressed
, it will show the animation while clicking the back button.
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
}
Firstly create one more animation i.e nothing.xml in your anim folder
nothing.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="0%"
android:toXDelta="0%" >
</translate>
here is your slide_in.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="-100%"
android:toXDelta="0%" >
</translate>
and slide_out.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="0%"
android:toXDelta="100%" >
</translate>
Now call your NewActivity like this
startActivity(new Intent(CurrentActivity.this, NewActivity.class));
overridePendingTransition(R.anim.slide_in, R.anim.nothing);
and then on your back button click do this
finish();
overridePendingTransition(R.anim.nothing, R.anim.slide_out);