Android Application Resources-Animation Resources (I)

Source: Internet
Author: User
Tags repetition time in milliseconds

There are two types of animation resources:

Property Animation

You can create an animation by modifying the attribute values of objects related to the Animator class within the specified time.

View animation

There are two types of view animation Frames

Tween animation: creates an Animation by executing a series of conversions of a single image related to the animation class.

Frame animation: creates an animation by displaying image sequences related to the order of the AnimationDrawable class.

Property Animation

An animation is defined in the XML of the target object attribute to be modified, such as the background color or alpha value within the set time.

File location ):

Res/animator/filename. xml. The file name is used as the resource ID.

COMPILED resource type (compiled rsource datatype ):

The resource must be of the ValueAnimator, ObjectAnimator, or AnimatorSet type.

Resource reference ):

In Java code: R. animation. filename

In the XML file: @ [package:] animator/filename

SYNTAX (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>
...
</Set>
</Set>

This file must have a single heel element: either <set>, <objectAnimator>, or <valueAnimator>. You can organize the animation elements together into <set> elements, including other <set> elements.

Element (ELEMENTS ):

<Set>

A container that can contain other animation elements (<objectAnimator>, <valueAnimator>, or other <set> elements ). Represents an AnimatorSet object.

You can specify <set> nested labels to organize more Animations together. Each <set> can define its own ordered attributes.

ATTRIBUTES (ATTRIBUTES ):

Android: ordering

Key Attribute, which specifies the playing sequence of the animation in the set.

Value Description
Sequentially Play the animation in sequence in this group.
Together (default) Play the animation in the group set at the same time
 


<ObjectAnimator>

A specific animation attribute of an object within a specific set time represents an ObjectAnimator object.

ATTRIBUTES (ATTRIBUTES ):

Android: propertyName

String type, required. This name is used to reference the object attributes of an animation. For example, you can specify the "alpha" or "backgroundColor" attribute for the View object. The ObjectAnimator element does not expose the target attribute, so the object cannot be set to an animation in the XML declaration. You must call the loadAnimator () method and setTarget () method to populate the animation XML resource with the target object containing this attribute.

Android: valueTo

Required for floating point type, integer type, or color value. It is the end value of the animation attribute. The color is represented by six hexadecimal numbers (for example, #333333 ).

Android: valueFrom

Floating point type, integer, or color value. It is the starting value of the animation attribute. If it is not specified, the animation starts to get the value using the get method of the property. The color is represented by a six-digit hexadecimal number (for example, #333333 ).

Android: duration

Integer type. Specifies the animation time in milliseconds. The default value is 300 milliseconds.

Android: startOffset

Integer type. The animation delay in milliseconds after the start () method is called.

Android: repeatCount

Integer type. Specifies the number of animation repetitions. If it is set to "-1", it indicates that it must be repeated infinitely or specify a positive integer. For example, if this parameter is set to 1, the animation must be repeated once after the first operation. Therefore, the animation must be played twice. The default value is 0, meaning no repetition.

Android: repeatMode

A positive integer. Specifies the behavior at the end of the animation. This attribute is effective only when android: repeatCount is set to a positive integer or "-1. If it is set to "reverse", the animation will be played reversely during each repetition. If it is set to "repeat", the animation will be played at the beginning of each repetition.

Android: valueType

Key attributes. If the value is a color value, you do not need to specify this attribute. The animation frame automatically processes the color value.

Value Description
IntType The animation value is an integer.
FloatType (default) The animation value is a floating point number.
 


<Animator>

Animation within the specified time. Represents a ValueAnimator object.

ATTRIBUTES (ATTRIBUTES ):

Android: valueTo

Float, integer, or color value, required. It is the animation end value. The color value is represented by a six-digit hexadecimal number (for example, #333333)

Android: valueFrom

Float, integer, or color value, required. It is the starting value of the animation. The color value is represented by a six-digit hexadecimal number (for example, #333333)

Android: duration

Integer. Specifies the animation playback time in milliseconds. The default value is 300 milliseconds.

Android: startOffset

Integer. The number of milliseconds after the specified start () method is called.

Android: repeatCount

Integer. Specifies the number of animation repetitions. If it is set to "-1", the animation repeats infinitely, or a positive integer is specified. For example, if it is set to "1", the animation will be played again after the initial operation, so the animation is played twice in total. The default value is 0, which means that the animation is repeated.

Android: repeatMode

Integer. It specifies the behavior that repeats when the animation ends. Android: repeatCount must be set as a positive integer or "-1" before this attribute can take effect. If it is set to "reverse", the animation is played reversely during each replay. If it is set to "repeat", the animation is played at the starting position during each replay.

Android: valueType

Key Attribute. If the value is color, you do not need to specify this attribute. Because the animation frame automatically processes the color value

Value Description
IntType The animation value is an integer.
FloatType (default) The animation value is a floating point number.
 


EXAMPLE ):

This XML file is saved in res/animator/property_animator.xml:

<Set android: ordering = "sequentially">
<Set>
<ObjectAnimator
Android: propertyName = "x"
Android: duration= "500"
Android: valueTo = "400"
Android: valueType = "intType"/>
<ObjectAnimator
Android: propertyName = "y"
Android: duration= "500"
Android: valueTo = "300"
Android: valueType = "intType"/>
</Set>
<ObjectAnimator
Android: propertyName = "alpha"
Android: duration= "500"
Android: valueTo = "1f"/>
</Set>

To run the animation, you must fill the XML resource in the Code with an AnimatorSet object, and set all the animations for the target object before starting the animation set. You can call the setTarget method to conveniently set a single object to all sub-objects of the AnimatorSet object. The Code is as follows:

AnimatorSet set = (AnimatorSet) AnimatorInflater. loadAnimator (myContext, R. anim. property_animator );

Set. setTarget (myObject); set. start ();

 
From FireOfStar's column

Related Article

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.