How to Change the Android Startactivity() Transition Animation

Can I change the Android startActivity() transition animation?

In the same statement in which you execute finish(), execute your animation there too. Then, in the new activity, run another animation. See this code:

fadein.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:fillAfter="true">
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="500"/> //Time in milliseconds
</set>

In your finish-class

private void finishTask() {
if("blabbla".equals("blablabla"){
finish();
runFadeInAnimation();
}
}

private void runFadeInAnimation() {
Animation a = AnimationUtils.loadAnimation(this, R.anim.fadein);
a.reset();
LinearLayout ll = (LinearLayout) findViewById(R.id.yourviewhere);
ll.clearAnimation();
ll.startAnimation(a);
}

fadeout.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="500"/>
</set>

In your new Activity-class you create a similiar method like the runFadeAnimation I wrote and then you run it in onCreate and don't forget to change the resources id to fadeout.

How to apply slide animation between two activities in Android?

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);

new Handler().postDelayed(new Runnable() {
public void run() {

/* Create an intent that will start the main activity. */
Intent mainIntent = new Intent(SplashScreen.this,
ConnectedActivity.class);
mainIntent.putExtra("id", "1");

//SplashScreen.this.startActivity(mainIntent);
startActivity(mainIntent);
/* Finish splash activity so user cant go back to it. */
SplashScreen.this.finish();

/* Apply our splash exit (fade out) and main
entry (fade in) animation transitions. */
overridePendingTransition(R.anim.mainfadein,R.anim.splashfadeout);
}
}, SPLASH_DISPLAY_TIME);
}

Activity transition in Android

You can do this with Activity.overridePendingTransition(). You can define simple transition animations in an XML resource file.

How to switch activity without animation in Android?

You can create a style,

 <style name="noAnimTheme" parent="android:Theme">
<item name="android:windowAnimationStyle">@null</item>
</style>

and set it as theme for your activity in the manifest:

   <activity android:name=".ui.ArticlesActivity" android:theme="@style/noAnimTheme">
</activity>

You can also define a style to specify custom entry and exit animations.
http://developer.android.com/reference/android/R.attr.html#windowEnterAnimation

Open and Close transition animation to each activity

overridePendingTransition(R.anim.right_in, R.anim.left_out);
Use this line after startActivity();
right_in - anim to start layout
right_out - anim to close layout

Dont forget to swith on animation in developer setting!!

How do I Change the default animation when changing activity?

You may refer to the example in apidemos's directory, which uses overridePendingTransition to show custom animation. Also another post related to this topic: Can I change the Android startActivity() transition animation?



Related Topics



Leave a reply



Submit