Let's take a look at the pseudocode of the animation configuration file in android:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator"> <alpha /> <rotate /> <scale/> <translate/> </set> <?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator"> <alpha /> <rotate /> <scale/> <translate/></set>
Now let's take it easy to understand:
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android
Declare the namespace of xml, xmlns (abbreviation of xml namespace), and the alias schemas referenced by the colon is the xml constraint file, which specifies the elements (TAGS) in xml ), the attributes of the element and the relationship between the elements. After the namespace and the constraint file are declared, the resource can be referenced in the modified xml document, resources stored in apk/res/android can be accessed. For example, you can use "android:" to reference the attributes in <rotate/>, of course, you can also define your own resource file (such as test), you can use "test:" To reference it.
android:interpolator="@android:anim/decelerate_interpolator" android:interpolator="@android:anim/decelerate_interpolator"
First, understand that interpolator defines the rate of change of an animation, which enables the basic animation effects (scale, alpha, translate, and rotate) to accelerate, slow down, and repeat, in other words, the animation progress is controlled by Interpolator. The control effects include constant speed, positive acceleration, negative acceleration, and irregular speed change, the Interpolator interface has only one abstract method, getInterpolation (float input), which extends several other classes in the SDK.
Common Interpolator classes:
AccelerateInterpolator: the animation is accelerated from the beginning to the end.
DecelerateInterpolator: the animation starts from the beginning to the end, and the change rate is a deceleration process.
AccelerateDecelerateInterpolator: the animation starts from the beginning to the end, and the change rate is the process of accelerating and slowing down.
There are two types of animations in the android SDK,
One is Tween Animation (gradient Animation): By constantly performing image transformation on objects in the scene, such as translation, scaling, and rotation.
One is Frame Animation (Frame Animation): an image that can be completed through sequential playback.
Four types of animations in android
Four types of animations are the basic animation types provided by android. They can all be placed in the <set> </set> tag in the configuration file. How can we create an animation effect. See the following xml animation configuration file:
Step 1: Create a folder named anim under the res directory and create a new xml file under the folder.
Step 2: Add a namespace, that is, write the set tag and specify the animation controller (you can leave it empty ).
Step 3: Create and set the animation types and initial values.
Note that when the rotate label and the translate label are used together, put the rotate label before the translate label.
Attribute meaning of each tag
Description of the set tag attribute:
Android: shareInterpolator -- whether to share the plug-in. When sharing, all four subnodes use one plug-in.
Android: interpolator -- specifies an animation plug-in that uses system resources.
Android: fillEnabled -- when it is set to true, both fillAfter and fillBefroe will be true, and the fillBefore and fillAfter attributes will be ignored.
Android: fillAfter -- whether the animation is converted to a boolean value after the animation ends.
Android: fillBefore -- whether the animation is converted to a boolean value before the animation starts.
Android: repeatMode -- restart or reverse
Android: repeatCount -- number of repetitions integer
Android: duration -- animation duration integer
Android: startOffset -- long animation Interval
Android: zAdjustment -- defines the normal or top or bottom change of the zorder animation.
Description of scale label attributes:
Android: interpolator -- same as set attribute
Android: fromXScale-the extension size on the x coordinate when the animation starts (float 0.0 indicates shrinking to the minimum, and 1.0 indicates no shrinking)
Android: toXScale-likewise
Android: fromYScale-likewise
Android: toYScale-likewise
Android: duration-animation duration (int in milliseconds)
Android: animated TX-x position relative to the object at the beginning of the animation (0% ~ 100%)
Android: policty -- likewise
Android: fillEnabled -- same as set attribute
Android: fillBefore -- same as set attribute
Android: fillBefore -- same as set attribute
Android: fillAfter -- same as set attribute
Android: startOffset -- same as set attribute
Android: repeatCount -- same as set attribute
Android: repeatMode -- same as set attribute
Meaning of the rotate label attribute:
Android: fromDegrees-angle at the beginning of an animation (with positive and negative signs)
Android: toDegrees: The angle at the animation end (positive and negative)
Android: Rotate TX -- can be understood as the center of rotation (0% ~ 100%)
Android: policty -- likewise
Android: duration-animation duration (int in milliseconds)
Description of the alpha tag attribute:
Android: toAlpha-transparency at the animation end (float 0 indicates full transparency 1 indicates full opacity)
Android: duration-animation duration (int in milliseconds)
Android: fromAlpha-transparency at the beginning of the animation (float 0 indicates full transparency 1 indicates full opacity)
Description of the attributes of the translate Tag:
Android: fromXDelta-when the animation starts, the position integer on the X coordinate takes itself as the reference object by default.
Android: toXDelta-when the animation ends, the position integer on the X coordinate takes itself as the reference object by default.
Android: fromYDelta-when the animation starts, the position integer on the Y coordinate takes itself as the reference object by default.
Android: toYDelta-when the animation ends, the position integer on the Y coordinate takes itself as the reference object by default.
Of course, the attributes in scale, rotate, alpha, and translate are not limited to these attributes, but some of them are the same as those in the set tag, so they are not repeatedly written. Here, the simplest knowledge of android animation is complete. Next, we will continue to learn and continue to summarize.