Here's the code to do a nice smooth fade between two Activities..
Create a file called fadein.xml
in res/anim
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000" />
Create a file called fadeout.xml
in res/anim
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="2000" />
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.
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
If the fades are too slow for you, change android:duration
in the xml files above to something smaller.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…