Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flip card transition between two activities Android

Tags:

android

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!

like image 270
Chinmay Dabke Avatar asked Nov 13 '13 16:11

Chinmay Dabke


1 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!

like image 144
BossWalrus Avatar answered Nov 04 '22 21:11

BossWalrus