Knowing the animation and transition effects in Android Support Library V4
Knowing the animation and transition effects in Android Support Library V4
Overview:
Android Support Library is a collection library created to be compatible with the old version of the Android system.Among them, Support Library V4 provides developers with many powerful functions, including animation and transition effects.In this article, we will explore the animation and transition effects in Android Support Library V4, and provide some Java code examples to help readers better understand and apply these features.
1. Animation effect
1. Hirammphonic animation: You can use the ObjectAnimator class to achieve flat moving animation effects on the View.The following is an example code:
ObjectAnimator animator = ObjectAnimator.ofFloat(myView, "translationX", 0, 200);
animator.setDuration(1000);
animator.start();
This code will move the MyView view from the initial position of 200 pixels and complete the animation in 1 second.
2. Scaling animation: You can achieve the effect of zoom animation on the view by using the Objectanimator class.The following is an example code:
ObjectAnimator animator = ObjectAnimator.ofFloat(myView, "scaleX", 1f, 2f);
animator.setDuration(1000);
animator.start();
This code will zoom the MyView view twice as much as the original size on the X -axis and complete the animation in 1 second.
3. Transparency animation: You can achieve transparent animation effects on View by using the Objectanimator class.The following is an example code:
ObjectAnimator animator = ObjectAnimator.ofFloat(myView, "alpha", 1f, 0f);
animator.setDuration(1000);
animator.start();
This code will gradually change the MyView view from a completely visible state to completely transparent and complete the animation in 1 second.
Second, transition effect
1. Scene switch transition: You can use the transition effect of the smooth switch between scenes with the transitionManager class.The following is an example code:
Scene scene1 = Scene.getSceneForLayout(myLayout, R.layout.layout1, context);
Scene scene2 = Scene.getSceneForLayout(myLayout, R.layout.layout2, context);
TransitionManager.go(scene2, new ChangeBounds());
This code will play a smooth transition animation in the MyLayout container and switch the layout to Layout2.
2. Sharing element transition: You can use the transition effect between sharing elements with the transitionSet class and the PAIR class.The following is an example code:
View sharedView = findViewById(R.id.sharedView);
TransitionSet transitionSet = new TransitionSet();
transitionSet.addTransition(new ChangeBounds());
transitionSet.addTransition(new ChangeImageTransform());
transitionSet.addTarget(sharedView);
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this,
Pair.create(sharedView, "sharedView"));
startActivity(intent, options.toBundle());
This code will achieve the transition effect of sharing elements in the transition animation of Activity. Among them, the view of "IDView" will be shared and animated during transition.
in conclusion:
The animation and transition effect function in Android SUPPPORT LIBRARY V4 provides developers' rich and flexible choices, which can add a richer interactive experience to the application.By using these characteristics, developers can easily achieve various animation and transition effects, bringing users a cooler and smoother interface change to users.