Brief introduction
属性动画包含:ObjectAnimator 动画的执行类ValueAnimator 动画的执行类AnimatorSet 用于控制一组动画的执行:线性,一起,每个动画的先后执行等。AnimatorInflater 用户加载属性动画的xml文件
Objectanimator Single attribute animation
Zoom x axis: ScaleX
Objectanimator (). Offloat (ImageView, "ScaleY", 1.0f,0.0f). Setduration (+). Start ();
Scaling y-axis: ScaleY
Objectanimator (). Offloat (ImageView, "ScaleX", 1.0f,0.0f). Setduration (+). Start ();
Rotate animation (x-axis): RotationX
Objectanimator (). Offloat (ImageView, "RotationX", 0.0f,360f). Setduration (+). Start ();
Rotate animation (Y-axis): RotationY
Objectanimator (). Offloat (ImageView, "RotationY", 0.0f,360f). Setduration (+). Start ();
Rotate Animation (center point): Rotation
Objectanimator (). Offloat (ImageView, "rotation", 0.0f,360f). Setduration (+). Start ();
Fade: Alpha
Objectanimator (). Offloat (ImageView, "alpha", 1.0f,0.0f). Setduration (+). Start ();
Displacement animation (x-axis):
Objectanimator (). Offloat (ImageView, "Translationx", 0.0f,100.0f). Setduration (3000);
Displacement animation (y-axis):
Objectanimator (). Offloat (ImageView, "Translationy", 0.0f,100.0f). Setduration (3000);
The code is implemented as follows
imageView.clearAnimation(); ObjectAnimator objectAnimator=new ObjectAnimator().ofFloat(imageView,"translationX",0.0f,100.0f,0.0f,100.0f).setDuration(3000); objectAnimator.start();
Implemented in XML
- You first need to create a new animator folder under the Res folder, where the XML file is defined as follows
<?xml version= "1.0" encoding= "Utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android: Duration="> " <objectanimatorandroid:propertyname="ScaleX"android:repeatcount= "-1" android:valuefrom="0.0f"android:valueto="1.0f"> </objectanimator></Set>
- The corresponding code is implemented in the following
Animator animatorObjext = AnimatorInflater.loadAnimator(this, R.animator.objectanimator); animatorObjext.setTarget(imageView2); animatorObjext.start();
Valueanimator
- The code is implemented as follows
ImageView2. Clearanimation();ImageView2. Setimageresource(R. Mipmap. IC_launcher);The property values here can be set as many valueanimator animator = Valueanimator as needed. Offloat(1.0F0.0F1.0F0.0F1.0F;//Set property valueAnimator. Settarget(IMAGEVIEW2);//Set Action objectAnimator. Setduration( the). Start();//Animation startsAnimator. Addupdatelistener(New Valueanimator. Animatorupdatelistener() {@Override public void Onanimationupdate (Valueanimator animation) { ImageView2. Setscaley(Float) Animation. Getanimatedvalue());//setting changes on the y-axisImageView2. Setscalex(Float) Animation. Getanimatedvalue());//Set changes on the x-axis} });
Propertyvaluesholder Combo Animation
- is to set up a number of different animations, and let them load just fine.
- The corresponding Code implementation
ImageView. Clearanimation();Propertyvaluesholder Scalex=propertyvaluesholder. Offloat("ScaleX",1,0,1);Propertyvaluesholder Scaley=propertyvaluesholder. Offloat("ScaleY",1,0,1);Propertyvaluesholder Rotattion=propertyvaluesholder. Offloat("Rotation",0, the);Objectanimator objectanimator2=new Objectanimator (). Ofpropertyvaluesholder(imageview,scalex,scaley,rotattion). Setduration( the);ObjectAnimator2. Start();
Animatorset Combo Animations (the order in which animations can be set)
- The corresponding code is as follows
Objectanimator objectanimator3=new Objectanimator (). Offloat(ImageView,"Translationx",0.0F100.0F0.0F100.0F. Setduration( the);Objectanimator objectanimator4=new Objectanimator (). Offloat(ImageView,"ScaleX",1,0,1). Setduration( the);Objectanimator objectanimator5=new Objectanimator (). Offloat(ImageView,"Rotation",0, the). Setduration( the);Animatorset animatorset=new Animatorset ();Set animation to execute Animatorset at the same time. Playtogether(OBJECTANIMATOR3,OBJECTANIMATOR4);Set the order in which animations are executed Animatorset. Play(OBJECTANIMATOR5). after(ObjectAnimator3);Animatorset. Start();
]
Animatorinflater an XML file that loads property animations
- XML or XML file under the new animator folder under the Res folder
- The corresponding XML file is defined as follows
<?xml version= "1.0" encoding= "Utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:o rdering="Together" android:duration="> " <!--ordering refers to whether the animation is played together or one after another -- <objectanimatorandroid:propertyname="ScaleX"android:valuefrom ="0.0"android:valueto="1.0"> </objectanimator> <objectanimatorandroid:propertyname= "ScaleY"android:valuefrom=" 0.0 "android:valueto=" 1.0 "> </objectanimator></Set>
- The corresponding logic code is as follows
imageView2.clearAnimation(); imageView2.setImageResource(R.mipmap.ic_launcher); Animator animatorMy = AnimatorInflater.loadAnimator(getApplicationContext(), R.animator.animatorinflater); animatorMy.setTarget(imageView2); animatorMy.start();
Android Animation--Properties Animation Property Animation