Posted By

BenClayton on 03/01/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

rogerodell


Android: Fade between two Activities


 / Published in: XML
 

  1. Here's the code to do a nice smooth fade between two Activities..
  2. Create a file called fadein.xml in res/anim
  3.  
  4. <?xml version="1.0" encoding="utf-8"?>
  5. <alpha xmlns:android="http://schemas.android.com/apk/res/android"
  6. android:interpolator="@android:anim/accelerate_interpolator"
  7. android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000" />
  8.  
  9.  
  10. Create a file called fadeout.xml in res/anim
  11.  
  12. <?xml version="1.0" encoding="utf-8"?>
  13.  
  14. <alpha xmlns:android="http://schemas.android.com/apk/res/android"
  15. android:interpolator="@android:anim/accelerate_interpolator"
  16. android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="2000" />
  17.  
  18.  
  19. If you want to fade from Activity A to Activity B, put the following in the onCreate method for Activity B. Before setContentView works for me.
  20.  
  21.  
  22.  
  23. overridePendingTransition(R.anim.fadein, R.anim.fadeout);
  24. If the fades are too slow for you, change android:duration in the xml files above to something smaller.

Report this snippet  

You need to login to post a comment.