0

It should be a pretty simple question that I cannot find through google or the docs for the life of me. How do I change the transition style of my activity?

From what I've heard, there are the grow, left/right and up/down transitions for presenting and dismissing activities, but I don't have a clue how to implement them.

RileyE
  • 10,874
  • 13
  • 63
  • 106

2 Answers2

2

WHen you are doing:

startActivity(intent);

just put:

startActivity(intent);
overridePendingTransition(animIn, animOut);

animIn and animOut are ints that you can just define in anim resources folder for example:

slideInLeft.xml:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="100%p" android:toXDelta="0%p"
    android:duration="@android:integer/config_longAnimTime" />

slideOutLeft.xml:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0" android:toXDelta="-100%p"
    android:duration="@android:integer/config_longAnimTime" />

And when you want to return to the first activity you need to do the same but in finish method of activity:

finish();
overridePendingTransition(animIn, animOut);
PaNaVTEC
  • 2,505
  • 1
  • 23
  • 36
  • So, you do actually have to do the whole `overridePendingTransition`? I did see that in this post: http://stackoverflow.com/questions/3389501/activity-transition-in-android – RileyE Feb 15 '13 at 16:39
  • If you always want to use an override, I find it useful to override startActivity to call call super.startActivity then overridePendingTransition. Same with finish. It prevents you from forgetting somewhere. – Gabe Sechan Feb 15 '13 at 16:41
  • @GabeSechan Well, I'd love to not have to use an override, but what does overriding `startActivity` give me? Just a place to do the `overridePendingTransition` call? – RileyE Feb 15 '13 at 16:54
  • Yes. Basically it lets you just call startActivity elsewhere in your code, so if you have multiple transitions you don't have to remember it every time. Also, there may be some built in resources for transitions, you'd have to look in the android.R namespace. I just don't know of any. – Gabe Sechan Feb 15 '13 at 18:09
1

You can use activity.overridePendingTransition. It takes an enter and exit animation resource ids.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Eesh. That's brutal that you have to design your own, instead of having built in animations. – RileyE Feb 15 '13 at 16:39