Although after the Android 5.0 introduced a new way of transition animations, but usually only used in specific situations, the activity. The overridePendingTransition () general mode transition animation is still very common.
The principle of analysis
startActivity(Intent(this,SecondActivity::class.java))
overridePendingTransition(enterAnim, exitAnim)
Copy the code
OverridePendingTransition has two parameters, the first parameter (enterAnim) is applied to SecondActivity into screen visible area effect, the second parameter (exitAnim) is applied to the current Activity left screen visible area.
Schematic diagram
RightIn: Slide into the screen from the right (default on iOS)
By default, the new Activity enters the display area from the right (R) and the current Activity leaves the display area from the left (L).
EnterAnim (activity_right_to_left_enter.xml) : X axis from 100% to 0
<? xml version="1.0" encoding="utf-8"? > <set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromXDelta="100%"
android:toXDelta="0" />
</set>
Copy the code
ExitAnim (activity_right_to_left_exit.xml) : X axis from 0 to -100%
<? xml version="1.0" encoding="utf-8"? > <set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromXDelta="0"
android:toXDelta="100%" />
</set>
Copy the code
use
startActivity(Intent(this,SecondActivity::class.java))
overridePendingTransition(R.anim.activity_right_to_left_enter, R.anim.activity_right_to_left_exit)
Copy the code
BottomIn: Pops the Activity from the bottom (common effect)
Normally a new Activity pops up from the bottom, that is, from the B area to the visible area of the screen, and the current Activity remains unchanged. EnterAnim (activity_bottom_to_top_enter.xml) : Y axis from 100% to 0
<? xml version="1.0" encoding="utf-8"? > <set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="100%"
android:toYDelta="0" />
</set>
Copy the code
ExitAnim (no_im.xml) : The Y-axis remains unchanged
<? xml version="1.0" encoding="utf-8"? > <set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="0"
android:toYDelta="0"/>
</set>
Copy the code
use
startActivity(Intent(this,SecondActivity::class.java))
overridePendingTransition(R.anim.activity_bottom_to_top_enter, R.anim.no_anim)
Copy the code
RightOut (same as RightIn, iOS default)
Finish () transitions to startActivity. OverridePendingTransition has two parameters, the first parameter (enterAnim) is applied to an Activity into screen visible area effect, the second parameter (exitAnim) is applied to the current Activity left screen visible area.
The default finish animation for iOS is the current Activity from the visible area of the screen to the R area, and the previous Activity from the L area to the visible area of the screen.
EnterAnim (activity_left_to_right_enter.xml) : X axis from -100% to 0
<? xml version="1.0" encoding="utf-8"? > <set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromXDelta="100%"
android:toXDelta="0" />
</set>
Copy the code
ExitAnim (activity_left_to_right_exit.xml) : X axis from 0 to 100%
<? xml version="1.0" encoding="utf-8"? > <set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromXDelta="0"
android:toXDelta="100%" />
</set>
Copy the code
use
finish()
overridePendingTransition(R.anim.activity_left_to_right_enter, R.anim.activity_left_to_right_exit)
Copy the code
BottomOut (corresponding to BottomIn, common effect)
The effect of sliding out from the bottom of the screen is that the current Activity slides out of the visible area of the screen from the bottom, the previous Activity stays the same, and unlike BottomIn, enterAnim doesn’t need to animate because the previous Activity is already behind the screen, Just change the effect of the current Activity disappearing. ExitAnim (activity_top_to_bottom_exit.xml) : Y axis from 0 to 100%
<? xml version="1.0" encoding="utf-8"? > <set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="0%"
android:toYDelta="100%" />
</set>
Copy the code
use
finish()
overridePendingTransition(0, R.anim.activity_top_to_bottom_exit)
Copy the code
Complete sample code
Github.com/taoweiji/Ac…