Fadein.xml file:
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="500" />
Fadeout.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="500" />
Main activity class starts new activity when button is pressed:
Intent myIntent = new Intent(this, OtherActivity.class);
this.startActivity(myIntent);
In OtherActivity class:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
setContentView(R.layout.view);
}
It doesn’t work – activities doesn’t slide, it just opens instantly. What’s wrong?
There can be two possibilities if the activity just opens instantly… 1) is either the animations are disabled from settings on the device or emulator on which you running/testing your app or 2) is that the time of animation is also small/less means 500 Milli seconds so may be thats why fading effect is seeming like just opening effect
but i think the 1st point is your main problem.
Yes That is also the point as Alex Mentioned in his answer that
overridePendingTransition() method should be called after startActivity() from within the same activity mostly adjacent to startActivity() Method and not from the destination activity.