Animator Animation
Animation is used to make the UI dynamic and stylish.
There are two animation methods in Android:
One way is to fill in the animation tween animation, that is, you define a start and end, and the middle part is calculated by the program.
The other is frame-by-frame animation Frame Animation, which means that a frame-by-frame player becomes an animation when it is connected.
Animation effects:
1. Mobile (Translation)
2. Transparency (alpha)
3. Rotate)
4. Scale)
Now we will explain it using examples: The following implementations are implemented using code (objectanimator)
1. Mobile (Translation)
Main Code [Java]
Animatorset set = new animatorset ();
Objectanimator anim = objectanimator. offloat (phone, "translationx",-500f, 0f );
Anim. setduration (2000 );
Objectanimator anim3 = objectanimator. offloat (phone, "translationx", 0f,-500f );
Anim3.setduration (2000 );
Objectanimator anim2 = objectanimator. offloat (phone, "translationy", 0f,-500f );
Anim2.setduration (2000 );
Objectanimator anim4 = objectanimator. offloat (phone, "translationy",-500f, 0f );
Anim4.setduration (2000 );
Animatorset set3 = new animatorset ();
Set3.play (anim4). Before (anim3 );
Animatorset set2 = new animatorset ();
Set2.play (anim2). Before (set3 );
Set. Play (anim). Before (set2 );
Set. Start ();
Animatorset set = new animatorset ();
Objectanimator anim = objectanimator. offloat (phone, "translationx",-500f, 0f );
Anim. setduration (2000 );
Objectanimator anim3 = objectanimator. offloat (phone, "translationx", 0f,-500f );
Anim3.setduration (2000 );
Objectanimator anim2 = objectanimator. offloat (phone, "translationy", 0f,-500f );
Anim2.setduration (2000 );
Objectanimator anim4 = objectanimator. offloat (phone, "translationy",-500f, 0f );
Anim4.setduration (2000 );
Animatorset set3 = new animatorset ();
Set3.play (anim4). Before (anim3 );
Animatorset set2 = new animatorset ();
Set2.play (anim2). Before (set3 );
Set. Play (anim). Before (set2 );
Set. Start ();
Explanation: anim is moving from-500f to the current position (X axis );
Anim3 is the position from the current position to-500f (X axis );
Anim2 is the position that moves-500f from the current position (Y axis );
Anim 4 is to move from-500f to the current position (Y axis );
[Java]
Animatorset set3 = new animatorset ();
Set3.play (anim4). Before (anim3 );
Animatorset set2 = new animatorset ();
Set2.play (anim2). Before (set3 );
Set. Play (anim). Before (set2 );
Set. Start ();
Animatorset set3 = new animatorset ();
Set3.play (anim4). Before (anim3 );
Animatorset set2 = new animatorset ();
Set2.play (anim2). Before (set3 );
Set. Play (anim). Before (set2 );
Set. Start.
2. Transparency (alpha)
Main Code
[Java]
Animatorset set = new animatorset ();
Objectanimator anim = objectanimator. offloat (phone, "Alpha", 1f, 0f );
Anim. setduration (2000 );
Objectanimator anim2 = objectanimator. offloat (phone, "Alpha", 0f, 1f );
Anim2.setduration (2000 );
Set. Play (anim). Before (anim2 );
Set. Start ();
Animatorset set = new animatorset ();
Objectanimator anim = objectanimator. offloat (phone, "Alpha", 1f, 0f );
Anim. setduration (2000 );
Objectanimator anim2 = objectanimator. offloat (phone, "Alpha", 0f, 1f );
Anim2.setduration (2000 );
Set. Play (anim). Before (anim2 );
Set. Start ();
Explanation: anim is visible to invisible;
Anim is invisible;
3. Rotate)
Main Code
[Java]
Nimatorset set = new animatorset ();
Objectanimator anim = objectanimator. offloat (phone, "rotationx", 0f, 180f );
Anim. setduration (2000 );
Objectanimator anim2 = objectanimator. offloat (phone, "rotationx", 180f, 0f );
Anim2.setduration (2000 );
Objectanimator anim3 = objectanimator. offloat (phone, "rotationy", 0f, 180f );
Anim3.setduration (2000 );
Objectanimator anim4 = objectanimator. offloat (phone, "rotationy", 180f, 0f );
Anim4.setduration (2000 );
Set. Play (anim). Before (anim2 );
Set. Play (anim3). Before (anim4 );
Set. Start ();
Animatorset set = new animatorset ();
Objectanimator anim = objectanimator. offloat (phone, "rotationx", 0f, 180f );
Anim. setduration (2000 );
Objectanimator anim2 = objectanimator. offloat (phone, "rotationx", 180f, 0f );
Anim2.setduration (2000 );
Objectanimator anim3 = objectanimator. offloat (phone, "rotationy", 0f, 180f );
Anim3.setduration (2000 );
Objectanimator anim4 = objectanimator. offloat (phone, "rotationy", 180f, 0f );
Anim4.setduration (2000 );
Set. Play (anim). Before (anim2 );
Set. Play (anim3). Before (anim4 );
Set. Start ();
Explanation: anim changes from 0 degrees to 180 degrees (X axis)
Anim2 changes from 180 degrees to 0 degrees (X axis)
Anim3 from 0 degrees to 180 degrees (Y axis)
Anim4 changes from 180 degrees to 0 degrees (Y axis)
[Java]
Set. Play (anim). Before (anim2 );
Set. Play (anim3). Before (anim4 );
Set. Play (anim). Before (anim2 );
Set. Play (anim3). Before (anim4); in this way, both X and Y are rotated at the same time.
4. Scale)
Main Code
[Java]
Animatorset set = new animatorset ();
Objectanimator anim = objectanimator. offloat (phone, "scalex", 1f );
Anim. setduration (1000 );
Objectanimator anim2 = objectanimator. offloat (phone, "scalex", 0.5f );
Anim2.setduration (1000 );
Objectanimator anim3 = objectanimator. offloat (phone, "scaley", 1f );
Anim3.setduration (1000 );
Objectanimator anim4 = objectanimator. offloat (phone, "scaley", 0.5f );
Anim4.setduration (1000 );
Objectanimator anim5 = objectanimator. offloat (phone, "scalex", 0.5f );
Anim5.setduration (1000 );
Objectanimator anim6 = objectanimator. offloat (phone, "scalex", 1f );
Anim6.setduration (1000 );
Objectanimator anim7 = objectanimator. offloat (phone, "scaley", 0.5f );
Anim7.setduration (1000 );
Objectanimator anim8 = objectanimator. offloat (phone, "scaley", 1f );
Anim8.setduration (1000 );
Animatorset set3 = new animatorset ();
Set3.play (anim5). Before (anim6 );
Animatorset set2 = new animatorset ();
Set2.play (anim2). Before (set3 );
Animatorset set4 = new animatorset ();
Set4.play (anim7). Before (anim8 );
Animatorset set5 = new animatorset ();
Set5.play (anim4). Before (set4 );
Set. Play (anim). Before (set2 );
Set. Play (anim3). Before (set5 );
Set. Start ();
Animatorset set = new animatorset ();
Objectanimator anim = objectanimator. offloat (phone, "scalex", 1f );
Anim. setduration (1000 );
Objectanimator anim2 = objectanimator. offloat (phone, "scalex", 0.5f );
Anim2.setduration (1000 );
Objectanimator anim3 = objectanimator. offloat (phone, "scaley", 1f );
Anim3.setduration (1000 );
Objectanimator anim4 = objectanimator. offloat (phone, "scaley", 0.5f );
Anim4.setduration (1000 );
Objectanimator anim5 = objectanimator. offloat (phone, "scalex", 0.5f );
Anim5.setduration (1000 );
Objectanimator anim6 = objectanimator. offloat (phone, "scalex", 1f );
Anim6.setduration (1000 );
Objectanimator anim7 = objectanimator. offloat (phone, "scaley", 0.5f );
Anim7.setduration (1000 );
Objectanimator anim8 = objectanimator. offloat (phone, "scaley", 1f );
Anim8.setduration (1000 );
Animatorset set3 = new animatorset ();
Set3.play (anim5). Before (anim6 );
Animatorset set2 = new animatorset ();
Set2.play (anim2). Before (set3 );
Animatorset set4 = new animatorset ();
Set4.play (anim7). Before (anim8 );
Animatorset set5 = new animatorset ();
Set5.play (anim4). Before (set4 );
Set. Play (anim). Before (set2 );
Set. Play (anim3). Before (set5 );
Set. Start ();
Explanation: anim starts from the original size (X axis)
Anim2 scales to the original 1/2 (X axis)
Anim3 starts from the original size (Y axis)
Anim4 scales to the original 1/2 (Y axis)
Anim5 is enlarged from the original 1/2 (X axis)
Anim6 zoom in to the original size (X axis)
Anim7 is enlarged from the original 1/2 (Y axis)
Anim8 zoom in to the original size (Y axis)