user1018043 user1018043 - 1 year ago 89
Android Question

Animation between Activity with Android

i need to understand animation on Android.

For example, my application starts with an activity with a button in the bottom, when the user click on the button i want that another activity appears with an animation from bottom to top and i want that the button becomes the "header" of this second activity.

How can i achieve this?

Thank You


Thank you to DecodeGnome for the answer! It works!

But i have some problem with the animation when i want to close this activity, i create a anim_out.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="">
android:duration="300" />

but this doesn't work (the second parameter of overridePendingTransition what is used for?).

I try to call a new overridePendingTransition in onStop() function:

public void onStop(){
overridePendingTransition(R.anim.top_to_bottom, R.anim.top_to_bottom);


But when i call finish to the second activity, i still see the default animation (from left to right)!

Thank you again to who'll help me.

Answer Source

1) Create a folder called anim in res folder

2) Add 2 new XML animations there (example, anim_in.xml & anim_out.xml)

3) put this line of code in the new activities onCreate:

overridePendingTransition(R.anim.anim_in, R.anim.anim_out);

Anim_in.xml example:

<?xml version="1.0" encoding="utf-8"?>

        android:duration="300" />

4) Place the button (header) in the top of the layout of the second activity.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download