Laziness, like rust, consumes the body more than toil; The key that is often used is always shiny. --Franklin
This content: Animation animation
First, the implementation of the animation in Android in two ways, one way is tween animation Tween Animation, that is to say you define a start and end, the middle part of the program is calculated. The other is called frame Animation frames, that is, a frame of a frame of the link to play becomes an animation. and the mechanism of film is very similar, below we learn one by one.
The following official documents are referenced
From the graph we can know that the direct subclass of Animation has AlphaAnimation,AnimationSet, RotateAnimation, scale Animation, TranslateAnimation. where AnimationSet contains a series of Animation.
Tween animation is the process of manipulating a control so that it exhibits rotation (), gradient, move, and zoom. We can define animations as XML, or we can encode implementations.
Third, Tween Animation common node properties
properties [Type]
|
Function |
Note |
| Duration[long] |
Animation duration |
Millisecond units |
| Fillafter [Boolean] |
When set to True |
After the animation is executed, the control stays at the end of execution state |
| Fillbefore[boolean] |
When set to True |
After the animation is executed, the control stays in the state before execution |
| Repeatcount[int] |
Number of repetitions of an animation |
|
| Repeatmode[int] |
Define repetitive behavior |
1: Re-start 2:plays backward |
| Startoffset[long] |
Wait time before the animation executes |
Millisecond units |
|
|
|
|
|
|
Four,alpha gradient Transparency animation effect ( range between 0.0 and 1.0, respectively, representing transparent and completely opaque)
| Android:fromalpha= "1.0" |
Represents the starting Alpha value |
Floating point value, range between 0.0 and 1.0 |
| Android:toalpha= "0.0" |
Represents the end alpha value |
Floating-point values, range also between 0.0 and 1.0. |
| android:duration= "500" |
Animation duration |
Millisecond units |
|
|
|
scale gradient size scaling animation effect ( floating point values, such as 1.0 means that there is no change in itself, 0.5 is reduced by one time at the start, and 2.0 is magnified by one times )
| Android:fromxscale |
Relative self-scaling in the x direction of the start |
Floating point value, range between 0.0 and 1.0 |
| Android:toxscale |
Relative self-scaling in the X-direction at the end |
|
| Android:fromyscale |
Relative self-scaling in the Y-direction of the start |
|
| Android:toyscale |
Relative self-scaling in the Y-direction of the end |
|
| Android:pivotx |
The axis point x coordinate of the zoom |
If you want to indicate that the pivot point is the center of the image, |
| Android:pivoty |
The y-coordinate of the pivot point of the scale |
You can define two attribute values as 0.5 or 50%. |
The Android:pivotx property represents the x-coordinate value of the center of rotation, and the Android:pivoty property represents the y-coordinate value of the rotation center.
These two properties are also represented in three ways,
The number represents the pixel value relative to its left edge, (absolute position positioning) Ainmation.absolute
The num% method represents the percentage relative to the left or top edge of itself, as opposed to the control itself (positioned)ainmation.relative_to_self
The Num%p method represents the percentage of the left or top edge relative to the parent container. (relative to parent control) Ainmation.relative_to_parenf
Vi. Translate picture conversion position move animation effect ( represents a horizontal, vertical displacement )
| Android:fromxdelta |
Position in the starting X direction |
Floating point, num%, num%p |
| Android:toxdelta |
Position at the end x direction |
|
| Android:fromyscale |
Position in the starting Y direction |
|
| Android:toydelta |
Position at the end of the y direction |
|
|
|
|
The above four properties all support three kinds of representations: floating-point number, num%, num%p
num% Way represents the percentage relative to the left or top edge of itself (as opposed to the control itself) 100% represents 1 time times the distance to move yourself
num%p mode represents the percentage of the left or top edge relative to the parent container. (relative to parent control)
Seven,rotate picture transfer rotation animation effect
| Android:fromdegrees |
Represents the starting angle |
Floating-point value, Unit: Degree |
| Android:todegrees |
Represents the end angle |
Floating-point value, Unit: Degree |
| Android:pivotx |
The x-coordinate of the center of rotation |
|
| Android:pivoty |
The y-coordinate value of the table rotation Center |
|
|
|
|
Let's take a look at an example, and the code is written in comments.
Here is the Res/layout/activity_main.xml layout file:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android:orien tation= "vertical" tools:context= "com.example.text.mainactivity$placeholderfragment" > <imageview android: Id= "@+id/image" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:src= "@drawable/ic_launcher" android:layout_weight= "1"/> <button android:id= "@+id/translate" Andro Id:layout_width= "Match_parent" android:layout_height= "wrap_content" android:text= "Test translate animation effect"/> < ; Button android:id= "@+id/alpha" android:layout_width= "match_parent" android:layout_height= "wrap_content "android:text=" Test alpha animation effect "/> <button android:id=" @+id/rotate "android:layout_width=" match_p Arent "android:layout_height=" Wrap_conteNT "android:text=" test rotate animation effect "/> <button android:id=" @+id/scale "android:layout_width=" match _parent "android:layout_height=" wrap_content "android:text=" Test scale animation effect "/> </LinearLayout>
here is the Mainactivity.java main interface file:
public class Mainactivity extends Activity implements Onclicklistener {Private button Translate;private button Alpha;priv Ate button rotate;private button scale;private ImageView image; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); image = (ImageView ) Findviewbyid (r.id.image), translate = (button) Findviewbyid (r.id.translate), alpha = (button) Findviewbyid (r.id.alpha ); rotate = (Button) Findviewbyid (r.id.rotate); scale = (button) Findviewbyid (R.id.scale); Translate.setonclicklistener (this), Alpha.setonclicklistener (This), Rotate.setonclicklistener (This), Scale.setonclicklistener (this);} @Overridepublic void OnClick (View v) {//Creates a Animationset object Animationset animationset = new Animationset (true); switch ( V.getid ()) {case r.id.alpha://creates a Alphaanimation object alphaanimation alphaanimation = new Alphaanimation (1, 0);// Sets the time (in milliseconds) that the animation executes alphaanimation.setduration (1000);//Adds the Alphaanimation object to the Animationset animationset.Addanimation (alphaanimation);//Use ImageView Startanimation method to start animation image.startanimation (Animationset); break;case R.id.translate:translateanimation translateanimation = new Translateanimation (animation.relative_to_self, 0f, animation.relative_to_self,0.5f, Animation.relative_to_self, 0f,animation.relative_to_self, 1.0f); Translateanimation.setduration (+); animationset.addanimation (translateanimation); Image.startanimation ( Animationset); break;case r.id.rotate:rotateanimation rotateanimation = new Rotateanimation (0, 360,Animation.RELATIVE _to_parent, 1f,animation.relative_to_parent, 0f); rotateanimation.setduration; Animationset.addanimation ( rotateanimation); image.startanimation (animationset); break;case r.id.scale:scaleanimation ScaleAnimation = new Scaleanimation (1, 0.1f, 1,0.1f, Animation.relative_to_self, 0.5f,animation.relative_to_self, 0.5f); Animationset.addanimation (scaleanimation); Animationset.setstartoffset (+); animationset.setduration (2000); Image.startanimation (Animationset);Break;}}}
here is the result of the operation:
< Span style= "Color:rgb (51,51,51); font-family:arial; font-size:18px; line-height:26px ">
Ben said here, thank you all!
26th: Android Animation