Reputation: 311
I would like to add an animation before the opening of a new Android Empty Activity. Something like a chroma-keyed video played on top of the current activity and at the end of it, the secondary activity opens up.
Upvotes: 0
Views: 211
Reputation: 1414
After your startActivity method use the overridePendingTranistion and put the animations in it
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(ActivityA.this, ActivityB.class));
overridePendingTransition(R.anim.enter, R.anim.exit);
}
});
The xml animations are as follows enter.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="500"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
exit.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="500"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="-100%"
android:toYDelta="0%" />
</set>
Upvotes: 0
Reputation: 3756
You create a splash activity that includes your animation, and you implement an AnimationListener. Inside the method onAnimationEnd()
you create the intent that takes you to the second activity. Don't forget to set the splash activity as the Launcher activity on your manifest.
animationObject.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
Intent intent = new Intent (SplashActivity.this, MainActivity.class);
startActivity(intent); }
@Override
public void onAnimationRepeat(Animation animation) {
}
});
EDIT: if you want to play a video with media player instead you use a playback listener and run the same intent from onCompletion()
Upvotes: 1