Activity and fragment transitions in Lollipop (Android 5. 0) are based on some relatively new Android features called transitions. Introduced in KitKat, the transition framework provides a series of convenient API to provide animation between different UI states of the application. This framework is built around two key concepts: scenarios and transitions. The scenario defines the state given by the application UI, and the transition defines the animation changes between the two scenes.
When a scene changes, the transition has two main responsibilities:
Capture the state of each view in the start and end scene
Create an animator (Animator), based on different views that require animation from one scene to another.
This example explains how to use fragment transitions to create custom animations. Let’s start with the following steps:
Steps
Description
1
Use Android Studio to create an Android application, named Fragment Custom Animation, and package name cn.uprogrammer.fragmentcustomanimation. Exe.
2
Modify the res/layout/activity_main.xml file to add a TextView
3
Create a layout file for fragment_stack.xml under res/layout/, and define fragment tags and button tags
4
Create a subdirectory anim under res/, and add fragment_slide_left.xml, fragment_slide_left_exit.xml, fragment_slide_right_exit.xml and fragment_slide_left_enter.xml
5
Add fragment stack, fragment manager and onCreateView () to MainActivity.java
6
Start the Android emulator to run the application and verify the results of the application’s changes.