Android API Guides --- Animation Resources

Source: Internet
Author: User

Android API Guides --- Animation Resources
Animation Resources
Animation resources can define one of two types of animations:


Property Animation
Create an animation by modifying the object's attribute values by the time specified by the cartoonist.
Watch the animation
There are two types of animations that you can think of as the animation frame:


Tweens Animation: creates an animation by performing a series of transformations with a single animated image.
Frame Animation: or allows you to create an animation with the sequence of an AnimationDrawable image.
Property Animation


The animation defined in XML to modify the nature of the target object, such as the background color or alpha value, at the set time.


File Location:
RES/animation/filename. xml
The file name is used as the resource ID.
Compiled resource data type:
Resource pointer ValueAnimator, ObjectAnimator or AnimatorSet.
Resource reference:
In Java: R. animator. filename
In XML: @ [Package:] animation/file name

Syntax:

 

<set android:ordering=["together" | "sequentially"]>  <objectAnimator    android:propertyName="string"    android:duration="int"    android:valueFrom="float | int | color"    android:valueTo="float | int | color"    android:startOffset="int"    android:repeatCount="int"    android:repeatMode=["repeat" | "reverse"]    android:valueType=["intType" | "floatType"]/>  <animator    android:duration="int"    android:valueFrom="float | int | color"    android:valueTo="float | int | color"    android:startOffset="int"    android:repeatCount="int"    android:repeatMode=["repeat" | "reverse"]    android:valueType=["intType" | "floatType"]/>  <set>    ...  
The file must have a root element: either , Or . You can add an animation element to the <Settings> element, including Element.


ELEMENTS:

Containers that hold other animation elements ( , Or other <Settings> elements ). Indicates An AnimatorSet.
You can specify nested <Settings> labels to further group animations. Each You can define your own sorting attributes.


Attribute:


Android: ordering
Keyword. Specifies the playing sequence of the animation.
Value description
Sequential playback of animations in this set of Sequence
Together (default value), while playing this set of animation.

Specifies the specific attribute of the animation object end time. Indicates An ObjectAnimator.
Attribute:

Android: propertyName
String. Yes. The property of the object is animated and its name is referenced. For example, you can specify a view object "Alpha" and "backgroundColor ". The objectAnimator element does not expose the target attribute. However, you can do this without declaring the animation object in XML. You can call loadAnimator (inflatable animation XML resource) and setTarget () to set the target object containing this attribute.
Android: valueTo
Float, int or color .. Required. The animation attribute end value. The color is represented as a six-digit hexadecimal number (for example, #333333 ).
Android: valueFrom
Float, int or color. The starting value of the animation attribute. If not specified, the animation starts with the value obtained by the get method of the property. The color is represented as a six-digit hexadecimal number (for example, #333333 ).
Android: duration
Int type. Animation time in milliseconds. The default value is 300 milliseconds.
Android: startOffset
Int type. The number of animation latencies () is called after milliseconds.
Android: repeatCount
Int type. The number of repeated animations. It is set to "-1", with an infinite number of duplicates, or a positive integer. For example, the "1" value indicates that the animation is repeated once after the initial operation, so there are two times in the animation. The default value is "0", which means there are no duplicates.
Android: repeatMode
Int type. How to display the animation at the end of the animation. The repeatCount attribute of Android must be set to a positive integer or "-1. Set to "reverse". Each iteration has an animation in the opposite direction or "DUPLICATE" and has an animation loop starting from each time.
Android: valueType
Keyword. If the value is color, this attribute is not specified. Animation framework automatically processes color values
Value description
The animation value specified on IntType is an integer.
FloatType (default) specifies that the animation value is a floating point number.

Animation of the specified time amount. ValueAnimator.
Attribute:


Android: valueTo
Float, int or color. Yes. The animation end value. The color is represented as a six-digit hexadecimal number (for example, #333333 ).
Android: valueFrom
Float, int or color. Yes. The starting value of the animation. The color is represented as a six-digit hexadecimal number (for example, #333333 ).
Android: duration
Int type. Animation time in milliseconds. Ms is the default value.
Android: startOffset
Int type. The number of animation latencies () is called after milliseconds.
Android: repeatCount
Int type. The number of repeated animations. It is set to "-1", with an infinite number of duplicates, or a positive integer. For example, the "1" value indicates that the animation is repeated once after the initial operation, so there are two times in the animation. The default value is "0", which means there are no duplicates.
Android: repeatMode
Int type. How to display the animation at the end of the animation. The repeatCount attribute of Android must be set to a positive integer or "-1. Set to "reverse". Each iteration has an animation in the opposite direction or "DUPLICATE" and has an animation loop starting from each time.
Android: valueType
Keyword. If the value is color, this attribute is not specified. The animation frame automatically processes the color value.
Value description
The animation value specified on IntType is an integer.
FloatType (default) specifies that the animation value is a floating point number.
Example:
In the Save RES/animation/property_animator.xml file:

 

 

            
               
                
               
             
            
             
           
          
To run this animation, you must fill in the XML resource with the AnimatorSet object in the code, and then fill in the target object for all the animations before starting the animation set. Call to set the target () to all the sub-sets of the AnimatorSet as a convenient single target object. The following code demonstrates how to do this:

 

 

AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext,  R.anim.property_animator);set.setTarget(myObject);set.start();
You can also see:
Property Animation
The API demonstrates how to use the property animation system.
Watch the animation


The view animation framework supports tweens and frame-by-frame animations, which can be declared in Two XML files. The following sections describe how to use these two methods.
Tweens Animation


Execute transitions for animations defined in XML, such as rotating, fading, moving, and stretching graphs.


File Location:
RES/animation/filename. xml
The file name is used as the resource ID.
Compiled resource data type:
The resource points to an animation.
Resource reference:
In Java: R. anim. filename
In XML: @ [Package:] animation/file name
Syntax:

 

 

          <set xmlns:android="http://schemas.android.com/apk/res/android"  android:interpolator="@[package:]anim/interpolator_resource"  android:shareInterpolator=["true" | "false"] >  <alpha    android:fromAlpha="float"    android:toAlpha="float" />  <scale    android:fromXScale="float"    android:toXScale="float"    android:fromYScale="float"    android:toYScale="float"    android:pivotX="float"    android:pivotY="float" />  <translate    android:fromXDelta="float"    android:toXDelta="float"    android:fromYDelta="float"    android:toYDelta="float" />  <rotate    android:fromDegrees="float"    android:toDegrees="float"    android:pivotX="float"    android:pivotY="float" />  <set>    ...  
The file must have a root element: either <alpha>, <scale>, <translation>, <Rotation> or The group (or group) in which the element holds other animation elements (or even nested <Settings> elements ).


ELEMENTS:

Containers that hold other animation elements ( , , , ) Or other Element. Indicates An AnimationSet.
Attribute:


Android: interpolator
Interpolation resources. The interpolation tool is suitable for animation. This value must be a reference for a resource of the specified interpolation tool (the Class Name of the non-interpolation tool. You can use the default interpolation resource on the platform or create your own interpolation resource. For more information, see the following section.
Android: Movie interpolator
Boolean. True: If you want to share the same plug-in all sub-elements.

Fade in or fade out animation. Indicates An AlphaAnimation.
Attribute:


Android: fromAlpha
Floating. The starting opacity offset, where 0.0 is transparent and 1.0 is opaque.
Android: toAlpha
Floating. End opacity offset, where 0.0 is transparent and 1.0 is opaque.
For more attributes supported by <alpha>, see animated class references (where all XML attributes are referenced by the element inherrited ).



A scaling animation. You can specify the centers of an image that grows outward (or inward) by specifying Tx and Ty. For example, if these values are 0, 0 (upper left corner), all growth will go down and right. Represents ScaleAnimation.
Attribute:


Android: fromXScale
Floating. Start X dimensional deviation, where 1.0 is not changed.
Android: toXScale
Floating. End x dimension deviation, where 1.0 is not changed.
Android: fromYScale
Floating. The start y size deviation, of which 1.0 is not changed.
Android: toYScale
Floating. End Y type offset, where 1.0 is not changed.
Android: strongtx
Floating. To maintain the scaling of fixed objects.
Android: policty
Floating. To maintain the scaling of a fixed object.
For Supports more attributes to see the reference of the animation class (where all XML attributes are referenced by the element inherrited ).



Vertical and/or horizontal motion. The following attributes are supported in any of the following formats: The value ends with "%" from-100 to 100, indicating the percentage relative to itself; the value ends with-100 to 100 "% P, this indicates the percentage relative to its parent. A floating point value without a suffix indicates the absolute value. Indicates TranslateAnimation.
Attribute:


Android: fromXDelta
Float or percentage. The start X-axis offset. Represents any: In the pixel relative to the normal position (for example, "5"), in the percentage of width relative to the component (for example, "5% "), or the relative percentage to the width of the parent (for example, "5%").
Android: toXDelta
Float or percentage. End X axis offset. Represents any: In the pixel relative to the normal position (for example, "5"), in the percentage of width relative to the component (for example, "5% "), or the relative percentage to the width of the parent (for example, "5%").
Android: fromYDelta
Float or percentage. The start y-axis offset. Represents any: the percentage of pixels (for example, "5") relative to the normal position at the height of the component (for example, "5% "), or the relative percentage to the parent height (for example, "5% pairs ").
Android: toYDelta
Float or percentage. End Y axis offset. Represents any: the percentage of pixels (for example, "5") relative to the normal position at the height of the component (for example, "5% "), or the relative percentage to the parent height (for example, "5% pairs ").
For Supports more attributes to see the reference of the animation class (where all XML attributes are referenced by the element inherrited ).



A rotation animation. RotateAnimation.
Attribute:


Android: fromDegrees
Floating. Start angle, in degrees.
Android: toDegrees
Floating. End angle, in degrees.
Android: strongtx
Float or percentage. The X coordinate of the center of rotation. Represents any: Percentage of the left edge pixel relative to the object (for example, "5") and the left edge pixel relative to the object (for example, "5% "), or the relative percentage to the left edge of the parent container (such as "5% pairs").
Android: policty
Float or percentage. Y coordinate of the center of rotation. Represents any: Percentage of edge pixels (for example, "5") at the top of the object to the edge of the object (for example, "5% "), or the relative percentage to the top edge of the parent container (such as "5% pairs").
For more attributes supported by <Rotation>, see animated class references (where all XML attributes are referenced by the element inherrited ).


Example:
In the Save RES/animation/hyperspace_jump.xml file:

 

 

                    
                     
                        
                         
                        
                      
                     
                    
                   
                  
This application code will apply the animation to the ImageView and start Animation:

 

 

ImageView image = (ImageView) findViewById(R.id.image);Animation hyperspaceJump = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);image.startAnimation(hyperspaceJump);
You can also see:
2D graphics: tweens Animation
Interpolation


In XML, the interpolation tool is an animation modifier that affects the speed limit in the changed animation. This allows the existing animation effects to accelerate, slow down, repeat, and rebound.


The interpolation tool is applied to the animation element of Android: the interpolation property. Its value is the reference of the interpolation tool resource.


All available interpolation in Android is a subclass of the interpolation class. For each interpolation class, Android contains the following: You can apply the order in the android interpolation tool to the animation to reference public resources: interpolation attribute. The following table specifies resources for each plug-in:


ID of the interpolation Resource
AccelerateDecelerateInterpolator @ android: Animation/accelerate_decelerate_interpolator
AccelerateInterpolator @ android: Animation/accelerate_interpolator
AnticipateInterpolator @ android: Animation/anticipate_interpolator
AnticipateOvershootInterpolator @ android: Animation/anticipate_overshoot_interpolator
BounceInterpolator @ android: Animation/bounce_interpolator
CycleInterpolator @ android: Animation/cycle_interpolator
DecelerateInterpolator @ android: Animation/decelerate_interpolator
LinearInterpolator @ android: Animation/linear_interpolator
OvershootInterpolator @ android: Animation/overshoot_interpolator
Here is how you use these with one of Android: interpolation property:

 

 

                  
                     ...
                  
Custom Interpolation
If you are not satisfied with the interpolation provided by the platform (listed in the table above), you can create a modified property to customize the resource interpolation. For example, acceleration can be adjusted to the expected Interpolation Speed, or the adjusted cycle is periodic interpolation. To do this, you need to create your own resource in an XML file.
File Location:
RES/animation/filename. xml
The file name is used as the resource ID.
Compiled resource data type:
Resource pointer to the corresponding interpolation object.
Resource reference:
In XML: @ [Package:] animation/file name
Syntax:

 

 

                  <InterpolatorName xmlns:android="http://schemas.android.com/apk/res/android"  android:attribute_name="value"  />
If you do not apply any attributes, you will insert the functions provided by the platform (listed in the table above) that are identical.
ELEMENTS:
Note that for each interpolation implementation, the name starting with lowercase is used when the XML is defined.

The change rate starts and ends slowly but accelerates through the middle.
No attribute.

The change rate starts slowly and then accelerates.
Attribute:
Android: factor
Floating. Acceleration (1 by default ).

This change begins to throw and then moves forward.
Attribute:
Android: tension
Floating. The default value is 2 ).

Change the target values starting from backward, moving forward and forward, and then stabilize in the final value.
Attribute:
Android: tension
Floating. The default value is 2 ).
Android: extraTension
Floating. Multiply by the amount by the tension (1.5 by default ).

Changes rebounded at the end.
No attribute

Specifies the number of animations for the recurrence. The change rate follows the sine pattern.
Attribute:
Android: cycles
Integer. The number of cycles (1 by default.

The change rate is quickly opened, and then slowed down.
Attribute:
Android: factor
Floating. Speed Reduction (1 by default ).

The change rate is constant.
No attribute.

This change throws the cursor over the last value and then comes back.
Attribute:
Android: tension
Floating. The default value is 2 ).
Example:

 

In the Save RES/animation/my_overshoot_interpolator.xml file:

 

                       
                       
This animated XML will use interpolation:

 

 

                       
Frame Animation


An animation defined in XML shows the sequence of the image (such as a film ).


File Location:
RES/drawing/filename. xml
The file name is used as the resource ID.
Compiled resource data type:
The resource points to an AnimationDrawable.
Resource reference:
In Java: R. drawable. filename
In XML: @ [Package:] drawable. filename
Syntax:
                       <animation-list xmlns:android="http://schemas.android.com/apk/res/android"  android:oneshot=["true" | "false"] >  <item    android:drawable="@[package:]drawable/drawable_resource_name"    android:duration="integer" />

ELEMENTS:

Yes. This must be a root element. Contains one or more Element.
Attribute:


Android: oneshot
Boolean. "True", if you want to execute an animation; "false" loop animation.

A single animation frame. Must be a child element of an <animation list> element.
Attribute:


Android: drawable
Draw resources. This frame can be drawn.
Android: duration
Integer. The duration is displayed in milliseconds.
Example:
In the Save RES/animation/rocket. xml XML file:

 

 

                           
                           
                            
                           
                          
                         
The application code sets the animation as the background view and then plays the animation:

 

 

ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);rocketImage.setBackgroundResource(R.drawable.rocket_thrust);rocketAnimation = (AnimationDrawable) rocketImage.getBackground();rocketAnimation.start();

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.