I am trying to implement the Flip card
transition effect between two activities in my app by taking help from :
http://blog.robert-heim.de/karriere/android-startactivity-rotate-3d-animation-activityswitcher/.
But I couldn't understand what areActivitySwitcher.java
and Roatate3dAnimation.java
in the above mentioned site. I have two activities in my app between whom I want to show this transition effect. They are MainActivity.java
and About_us.java
.
Please explain the code with reference to my activities. I also searched on http://developer.android.com/training/animation/cardflip.html but in vain as it not for activities.
Thanks!

- 5,070
- 11
- 40
- 63
-
why don't you do it with the Fragments as like in the last link in developer web site. It's easier. – osayilgan Nov 13 '13 at 16:45
-
@osayilganThanks for your quick reply! But you got my question wrong. What I want to do is display a transition effect between two activities. – Chinmay Dabke Nov 13 '13 at 16:48
-
What didn't you understand in those classes ? It's quite clear. You just implement the Code respectively as Activity1 and Activity2 as your MainActivity and About_us activities. – osayilgan Nov 13 '13 at 17:02
-
@osayilgan All what I didn't understand is the use and implementation of `ActivitySwitcher.java` and `Rotate3dAnimation.java`. – Chinmay Dabke Nov 13 '13 at 17:17
-
possible duplicate of [Card Flip Animation between Activities](http://stackoverflow.com/questions/15309931/card-flip-animation-between-activities) – Fox Dec 17 '13 at 19:35
2 Answers
Disclaimer: This is not a an actual 3D Animation Flip. This merely imitates it, though some don't agree. Give it a try and if you like it, great! If you don't, my apologies.
In my early days of learning to code, I was having issues implementing a proper 3D Animation flip, so I went with this, it simulated it enough to satisfy my needs, but to each her/his own. To do what I did, first make sure that you have a folder called anim under your res folder for your project. Then you will need to create two xml files (I have mine called from_middle and to_middle). Below is the code for each of those:
from_middle.xml:
<?xml version="1.0" encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0.0" android:toXScale="1.0"
android:pivotX="50%"
android:fromYScale="1.0" android:toYScale="1.0"
android:pivotY="50%"
android:duration="500" />
to_middle.xml:
<?xml version="1.0" encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1.0" android:toXScale="0.0"
android:pivotX="50%"
android:fromYScale="1.0" android:toYScale="1.0"
android:pivotY="50%"
android:duration="500" />
After those are created, all you need is one line of code to run this animation, which you should be placed after you start your next activity:
overridePendingTransition(R.anim.from_middle, R.anim.to_middle);
Done! Now run it!

- 770
- 1
- 12
- 29
-
Thanks a lot for your efforts!! I'll definitely try it and let you know the results. – Chinmay Dabke Nov 13 '13 at 17:14
-
Weird.. it does for me. What happened? Please post your code so I can take a closer look – BossWalrus Nov 13 '13 at 18:10
-
I'm really sorry man! It works!!!!! It was an error from my side but now it works like a charm! Thanks a lot and sincere apologies for earlier. – Chinmay Dabke Nov 13 '13 at 18:22
-
Sweet! Not a problem, glad I could help! It took me forever to find help on that, so I'm more than happy to pass it on. Please accept the answer if you would be so inclined :) – BossWalrus Nov 13 '13 at 18:33
-
-
I found it elsewhere, I am currently looking for the source to give them a shout out! – BossWalrus Nov 13 '13 at 19:03
-
9This is not a flip-card animation. Flip card animations are 3 dimensional, and this is a simply a trick using 2 dimensional scale animations. It by no means gives the same effect. While some people may think it's "close enough", i definitely don't agree. – Gil Moshayof Feb 27 '14 at 11:06
-
Hi,Where exactly I need to place the overridePendingTransition(R.anim.from_middle, R.anim.to_middle); ? If I am calling Activity2 from Activity1 onclick of a button, then should I apply the same like, Intent intent = new Intent(Activity1.this,Activity2.class); startActivity(intent); overridePendingTransition(R.anim.from_middle, R.anim.to_middle); Because placing it here does not work for me. – akash89 Dec 20 '14 at 19:01
-
Please edit your answer warning users that this is not a flip card animation. – ikbal Jun 12 '16 at 20:15
Based on user1672053's answer, you need to add a start offset to the from_middle.xml
resource which is equal to the duration of the to_middle.xml
animation resource.

- 25,773
- 31
- 101
- 122