Android animation painter Animator and LayoutAnimator
Overview:
Compared with the Android Animation control, the Animation effect of the Animator and LayoutAnimator controls is not restored to the original state. Animator only uses a View object, similar to Animation. Animator can also be defined in xml, and objectAnimator needs to be used to define various Animation effects.
LayoutView is often used to add some special effects to the addition and deletion of controls, such as fade-in and fade-out.
DemoAnimator
Animator dynamic mode:
// Change the ObjectAnimator. ofFloat (mImageViewAnim, scaleX, 0.0f, 1.0f). setDuration (2000). start ();
In the static mode of Animator, you need to create a new animator folder under the res directory, and create an xml file in this folder. Mine is scale:
Load the R. animator. scale resource in the code
AnimatorSet set = (AnimatorSet) AnimatorInflater. loadAnimator (getApplicationContext (), R. animator. scale); set. setTarget (view); // animator changes the view State set permanently. start ();
LayoutAnimator
Public class layoutanimatoracti1_extends Activity {private Button mButtonAdd; private LinearLayout mLinearLayout; private int count; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. layout_animator); mButtonAdd = (Button) findViewById (R. id. button_addAnimator); mLinearLayout = (LinearLayout) findViewById (R. id. linear_layout); // defines a LayoutTransition, used to set various animation effects LayoutTransition transition = new LayoutTransition (); // transition. getDuration (2000); // when the child control is added, the animation effect is static R. animator. scale transition. setAnimator (LayoutTransition. APPEARING, AnimatorInflater. loadAnimator (getApplicationContext (), R. animator. scale); // when CHANGE_APPEARING is enabled, call the default state change animation effect transition. setAnimator (LayoutTransition. CHANGE_APPEARING, transition. getAnimator (LayoutTransition. CHANGE_APPEARING); // when the child control disappears, call the default animation effect transition that disappears. setAnimator (LayoutTransition. DISAPPEARING, transition. getAnimator (LayoutTransition. DISAPPEARING); // when CHANGE_APPEARING is called, the animation effect transition of state change is called by default when it disappears. setAnimator (LayoutTransition. CHANGE_DISAPPEARING, transition. getAnimator (LayoutTransition. CHANGE_DISAPPEARING); mLinearLayout. setLayoutTransition (transition); mButtonAdd. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {count ++; Button btn = new Button (getApplicationContext ()); // The LayoutParams class is a container ViewGroup used for the child view to convey its various attributes to the parent view (parent view. layoutParams params = new ViewGroup. layoutParams (ViewGroup. layoutParams. WRAP_CONTENT, ViewGroup. layoutParams. WRAP_CONTENT); btn. setLayoutParams (params); btn. setText (Button + count); // set the initial size of btn. setScaleX (0f); btn. setScaleY (0f); // Add a click event to the Button sub-control to be added: Click to delete your btn. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {mLinearLayout. removeView (v) ;}}); // Add the child control mLinearLayout to mLinearLayout. addView (btn );}});}}
Result demonstration: