Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android rotate animation between two activity?

Tags:

android

How to put rotate animation between two activities.when is startactivity and next activity is start with rotate animation

like image 692
Samir Mangroliya Avatar asked Oct 21 '11 18:10

Samir Mangroliya


1 Answers

Here's a tutorial on how to add an animation when transistioning between two activities. However, instead of using a translate animation like in the article, you'll want to use a rotate animation. For more information on animations, checkout this documentation.

Putting those two things together, here's what you need to do. First, where you make the call to start the new activity do this:

//Calls a new Activity  
startActivity(new Intent(this, NewActivity.class));  

//Set the transition -> method available from Android 2.0 and beyond  
overridePendingTransition(R.anim.rotate_out,R.anim.rotate_in);

Then create the following two animations in your xml:

rotate_out.xml

<?xml version="1.0" encoding="utf-8"?>   
<set xmlns:android="http://schemas.android.com/apk/res/android">  
   <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />  
   <rotate android:fromDegrees="0" android:toDegrees="90" android:pivotX="25%" />
</set>

rotate_in.xml

<?xml version="1.0" encoding="utf-8"?>   
<set xmlns:android="http://schemas.android.com/apk/res/android">  
   <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />  
   <rotate android:fromDegrees="90" android:toDegrees="0" android:pivotX="-25%" />
</set>

You can play with the fromDegrees, toDegrees, and pivotX values to get exactly what you'd like.

like image 169
Kurtis Nusbaum Avatar answered Nov 16 '22 09:11

Kurtis Nusbaum