YouTip LogoYouTip

Android Fragment Transitions

Activity and fragment transitions in Lollipop (Android 5.0) are built upon some relatively new Android features called Transitions. Introduced in KitKat, the Transition framework provides a convenient set of APIs for animating between different UI states in an application. This framework is built around two key concepts: scenes and transitions. A scene defines a given state of an application's UI, while a transition defines the animated change between two scenes. When a scene changes, a transition has two main responsibilities: * Capture the state of each view in the start and end scenes. * Create an Animator based on the differences between the views that need to be animated from one scene to the other. * * * ## Example This example explains how to use fragment transitions to create custom animations. Let's start by following the steps below: | Step | Description | | --- | --- | | 1 | Use Android Studio to create an Android application, named Fragment Custom Animation, with package name cn.uprogrammer.fragmentcustomanimation. | | 2 | Modify the res/layout/activity_main.xml file to add a TextView. | | 3 | Create a layout file named fragment_stack.xml under res/layout/, defining a fragment tag and a button tag. | | 4 | Create a subdirectory named 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 | In MainActivity.java, you need to add a fragment stack, fragment manager, and onCreateView(). | | 6 | Launch the Android emulator to run the application and verify the results of the changes made by the application. | The following is the content of the res/layout/activity_main.xml file, which includes a FrameLayout and a Button.
← Go Select StatementGo Nested If Statements β†’