Ym -- Android 5.0 learning Activity transition Animation
Preface
Activity Transition:
Three Transition types are provided:
Enter: A transition (animation) determines how all views in the activity enter the screen.
Exit: An exit transition (animation) determines how all views in an activity exit the screen.
Shared Element: A Shared element transition (animation) determines the transition between two activities and how to share views.
These transition animations are supported:
Explode-move the view in or out of the ground, slide from the middle of the screen-move the view in or out of the ground, fade from the edge of the screen (fade out) -add or remove a view by changing the opacity of the view on the screen)
On the basis of the above animation, you can also add and support transition of shared elements: (the effects of shared elements are based on the decomposition animation)
It is used to share the common elements of two acitifiers. The following effects are supported in Android 5.0:
ChangeBounds-change the layout boundary of the target view
Changeconbounds-crop the target view Boundary
ChangeTransform-change the scaling ratio and Rotation Angle of the target view
ChangeImageTransform-change the size and scaling ratio of the Target Image
Procedure:
1. Set the animation (two ways ):
1.1xml settings
When you define a theme that inherits the material style, use the android: windowContentTransitions attribute to enable the content conversion (effect) of the window ). You can also specify conversion between inbound, outbound, and shared elements:
Define a transition Animation:
1.2 code settings
// TransitionsgetWindow () is allowed (). requestFeature (Window. FEATURE_CONTENT_TRANSITIONS); // sets an exit transitiongetWindow (). setExitTransition (new Explode (); // new Slide () new Fade ()
Window. setEnterTransition (): set to enter the animation
Window. setExitTransition (): Set the exit effect.
Window. setSharedElementEnterTransition (): sets the entry animation for the shared element.
Window. setSharedElementExitTransition (): sets the exit animation of the shared element.
2. Activity jump method:
Enter exit animation jump:
startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
Share element jump:
To enable transition animation between two activities with a shared element:
1. Enable window content transition in your topic
2. Specify the transition of shared elements in your theme Style
3. Define your transition animation as an XML Resource
4. Use the android: transitionName attribute to specify the same name for the shared elements in the two la s (the name must not be wrong)
5. Use ActivityOptions. makeSceneTransitionAnimation () method
Code:
// Share jump
intent = new Intent(Transitions.this, Transitions4.class); startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this,view,"shareName").toBundle());
Jump target xml:
If multiple sharing elements exist:
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, Pair.create(view1, "agreedName1"), Pair.create(view2, "agreedName2"));
Try it ~!