Android Animation parsing--xml

Source: Internet
Author: User

Type of animation

Android animation is made up of four different types

in XML

Alpha Gradient Transparency Animation effect
Scale gradient dimension stretch animation effect
Translate picture conversion position move animation effect
Rotate picture Transfer rotation animation effect

In Javacode

Alphaanimation Gradient Transparency Animation effect
Scaleanimation Gradient Dimension Stretch animation effect
Translateanimation picture Conversion position Move animation effect
Rotateanimation Picture Transfer rotation animation effect

Android Animation mode

Animation There are two main modes of animation:
One is tweened animation (gradient animation)

XML in Javacode
Alpha Alphaanimation
Scale Scaleanimation

One is frame by frame (Picture conversion animation)

XML in Javacode
Translate translateanimation
Rotate Rotateanimation


<pre name= "code" class= "HTML" > <?xml version= "1.0" encoding= "Utf-8"?>
<set xmlns:android= "Http://schemas.android.com/apk/res/android" >
<alpha
Android:fromalpha= "0.1"
Android:toalpha= "1.0"
Android:duration= "3000"
/>
<!--transparency Controls animation effect Alpha
Floating-point values:
The Fromalpha property is the transparency at the beginning of the animation
Toalpha property is the transparency at the end of the animation
Description
0.0 indicates full transparency
1.0 means completely opaque
The above values take a number of float data types between 0.0-1.0

Long Integer value:
The Duration property is the duration of the animation
Description
The time is measured in milliseconds
-
</set>


<?xml version= "1.0" encoding= "Utf-8"?>
<set xmlns:android= "Http://schemas.android.com/apk/res/android" >
<scale
Android:interpolator= "@android: Anim/accelerate_decelerate_interpolator"
android:fromxscale= "0.0"
android:toxscale= "1.4"
android:fromyscale= "0.0"
android:toyscale= "1.4"
android:pivotx= "50%"
Android:pivoty= "50%"
Android:fillafter= "false"
Android:duration= "/>"
</set>
<!--size Scaling animation effect scale
Property: interpolator Specifies the insertion of an animation
In my experiment, using the resources in Android.res.anim, I found
There are three types of animation inserts:
Accelerate_decelerate_interpolator acceleration-deceleration animation insertion device
Accelerate_interpolator Acceleration-Animation insertion Device
Decelerate_interpolator deceleration-Animation insertion device
Other animations that belong to a specific animation effect
Floating-point values:

The Fromxscale property is the scaling dimension on the x-coordinate at the start of the animation
The Toxscale property is the scaling dimension on the x-coordinate at the end of the animation
The Fromyscale property is the scaling dimension on the y-coordinate at the start of the animation
The Toyscale property is the scaling dimension on the y-coordinate at the end of the animation

Description
Above four attribute values

0.0 means shrink to No
1.0 indicates normal no scaling
Values less than 1.0 indicate shrinkage
Values greater than 1.0 indicate magnification

The Pivotx property is the start position of the animation relative to the X coordinate of the object
The Pivoty property is the start position of the animation relative to the y-coordinate of the object

Description
The above two attribute values are taken from the 0%-100% value
50% is the midpoint position on the x or Y coordinate of the object

Long Integer value:
The Duration property is the duration of the animation
Description: The time is measured in milliseconds

Boolean-Value:
Fillafter property When set to True, the animation conversion is applied after the animation is finished
-


<?xml version= "1.0" encoding= "Utf-8"?>
<set xmlns:android= "Http://schemas.android.com/apk/res/android" >
<translate
Android:fromxdelta= "30"
Android:toxdelta= "-80"
Android:fromydelta= "30"
Android:toydelta= "300"
Android:duration= "2000"
/>
<!--translate position transfer animation effect
Integer value:
The Fromxdelta property is the position of the x-coordinate at the start of the animation
The Toxdelta property is the position of the x-coordinate at the end of the animation
The Fromydelta property is the position of the y-coordinate at the start of the animation
The Toydelta property is the position of the y-coordinate at the end of the animation
Attention:
Not specified Fromxtype toxtype fromytype toytype time,
The default is to use your own relative reference
Long Integer value:
The Duration property is the duration of the animation
Description: The time is measured in milliseconds
-
</set>

<?xml version= "1.0" encoding= "Utf-8"?>
<set xmlns:android= "Http://schemas.android.com/apk/res/android" >
<rotate
Android:interpolator= "@android: Anim/accelerate_decelerate_interpolator"
android:fromdegrees= "0"
Android:todegrees= "+350"
android:pivotx= "50%"
Android:pivoty= "50%"
Android:duration= "/>"
<!--rotate rotation animation effect
Property: interpolator Specifies the insertion of an animation
In my experiment, using the resources in Android.res.anim, I found
There are three types of animation inserts:
Accelerate_decelerate_interpolator acceleration-deceleration animation insertion device
Accelerate_interpolator Acceleration-Animation insertion Device
Decelerate_interpolator deceleration-Animation insertion device
Other animations that belong to a specific animation effect

Floating-point value:
Fromdegrees property is the angle of the object at the beginning of the animation
Todegrees property rotates the angle of the object at the end of the animation to be greater than 360 degrees


Description
When the angle is negative--indicates counterclockwise rotation
When the angle is positive--Indicates clockwise rotation
(Negative from--to positive: clockwise rotation)
(Negative from--to negative: counterclockwise rotation)
(Positive from--to positive: clockwise rotation)
(Positive from--to negative: counterclockwise rotation)

The Pivotx property is the start position of the animation relative to the X coordinate of the object
The Pivoty property is the start position of the animation relative to the y-coordinate of the object

Note: The above two attribute values are taken from the 0%-100% value
50% is the midpoint position on the x or Y coordinate of the object

Long Integer value:
The Duration property is the duration of the animation
Description: The time is measured in milliseconds
-
</set>

Animation effects in XML

<STRONG>
public static Animation Loadanimation (context context, int id)
The first parameter is context for the program
The second parameter ID is a reference to the animated XML file
Example:
myanimation= animationutils.loadanimation (this,r.anim.my_action);
Use the static method of the Animationutils class Loadanimation () to load the animated XML file in the XML </STRONG>

Defining animations in Java code

<strong>//defining an animation instance object in code
Private Animation Myanimation_alpha;
Private Animation Myanimation_scale;
Private Animation myanimation_translate;
Private Animation myanimation_rotate;

Initializes an instance object according to its own construction method
Myanimation_alpha=new alphaanimation (0.1f, 1.0f);

Myanimation_scale =new scaleanimation (0.0f, 1.4f, 0.0f, 1.4f,
Animation.relative_to_self, 0.5f, Animation.relative_to_self, 0.5f);

Myanimation_translate=new translateanimation (30.0f, -80.0f, 30.0f, 300.0f);

Myanimation_rotate=new rotateanimation (0.0f, +350.0f,
Animation.relative_to_self,0.5f,animation.relative_to_self, 0.5f);</strong>


XML code
<strong>//defining an animation instance object in code
Private Animation Myanimation_alpha;
Private Animation Myanimation_scale;
Private Animation myanimation_translate;
Private Animation myanimation_rotate;

Initializes an instance object according to its own construction method
Myanimation_alpha=new alphaanimation (0.1f, 1.0f);

Myanimation_scale =new scaleanimation (0.0f, 1.4f, 0.0f, 1.4f,
Animation.relative_to_self, 0.5f, Animation.relative_to_self, 0.5f);

Myanimation_translate=new translateanimation (30.0f, -80.0f, 30.0f, 300.0f);

Myanimation_rotate=new rotateanimation (0.0f, +350.0f,
Animation.relative_to_self,0.5f,animation.relative_to_self, 0.5f);</strong>

Defining an animation instance object in code
Private Animation Myanimation_alpha;
Private Animation Myanimation_scale;
Private Animation myanimation_translate;
Private Animation myanimation_rotate;

Initializes an instance object according to its own construction method
Myanimation_alpha=new alphaanimation (0.1f, 1.0f);

Myanimation_scale =new scaleanimation (0.0f, 1.4f, 0.0f, 1.4f,
Animation.relative_to_self, 0.5f, Animation.relative_to_self, 0.5f);

Myanimation_translate=new translateanimation (30.0f, -80.0f, 30.0f, 300.0f);

Myanimation_rotate=new rotateanimation (0.0f, +350.0f,
Animation.relative_to_self,0.5f,animation.relative_to_self, 0.5f);

Android Animation parsing--javacode

Alphaanimation
①alphaanimation Class object definitions

Java code
<STRONG> 1. Private Alphaanimation myanimation_alpha;</strong>

1. Private Alphaanimation Myanimation_alpha;

②alphaanimation Class object constructs

Java code
<strong>alphaanimation (float fromalpha, float toalpha)
The first parameter fromalpha is the transparency at the beginning of the animation
The second parameter, Toalpha, is the transparency at the end of an animation
Myanimation_alpha=new alphaanimation (0.1f, 1.0f);
Description
0.0 indicates full transparency
1.0 indicates full opacity </STRONG>

Alphaanimation (float fromalpha, float toalpha)
The first parameter fromalpha is the transparency at the beginning of the animation
The second parameter, Toalpha, is the transparency at the end of an animation
Myanimation_alpha=new alphaanimation (0.1f, 1.0f);
Description
0.0 indicates full transparency
1.0 means completely opaque

③ Setting Animation duration

Java code
<strong>myanimation_alpha.setduration (5000);
Set time duration is 5000 milliseconds </STRONG>

Myanimation_alpha.setduration (5000);
Set time duration to 5000 milliseconds

Scaleanimation

①scaleanimation Class object definitions

Java code
Private Alphaanimation Myanimation_alpha;

Private Alphaanimation Myanimation_alpha;

②scaleanimation Class object constructs

Java code
Scaleanimation (float FromX, float toX, float fromY, float toY,
int pivotxtype, float pivotxvalue, int p Ivotytype, float Pivotyvalue)
//The first parameter fromx the scaling dimension on the x-coordinate at the start of the animation
//The second parameter tox the scaling dimension on the x-coordinate at the end of the animation
// The third parameter, fromy, is the scaling dimension on the y-coordinate at the start of the animation
//fourth parameter toy the scaling dimension on the y-coordinate at the end of the animation
/* Description:
The above four attribute values
0.0 means that shrinking to no
1.0 means normal no scaling
value less than 1 .0 means that the contraction
value is greater than 1.0 for magnification
*/
//Fifth parameter Pivotxtype for animation on x-axis relative to object position type
//sixth parameter Pivotxvalue to animate the start of the x-coordinate of the object with respect to the item
// The seventh parameter Pivotxtype for the animation on the y-axis relative to the object position type
//eighth parameter pivotyvalue the start position of the animation relative to the object's y-coordinate
Myanimation_scale =new scaleanimation ( 0.0f, 1.4f, 0.0f, 1.4f,
Animation.relative_to_self, 0.5f, Animation.relative_to_self, 0.5f);

Scaleanimation (float FromX, float toX, float fromY, float ToY,
int Pivotxtype, float pivotxvalue, int pivotytype, float pivotyvalue)
The first parameter fromx is the scaling dimension on the x-coordinate at the start of the animation
The second parameter tox the scaling dimension at the end of the animation at the x-coordinate
The third parameter, fromy, is the scaling dimension on the y-coordinate at the start of the animation
The fourth parameter toy is the scaling dimension on the y-coordinate at the end of the animation
/* Description:
Above four attribute values
0.0 means shrink to No
1.0 indicates normal no scaling
Values less than 1.0 indicate shrinkage
Values greater than 1.0 indicate magnification
*/
The fifth parameter Pivotxtype for the animation on the x-axis relative to the object position type
The sixth parameter pivotxvalue the start position of the animation relative to the x-coordinate of the object
The seventh parameter Pivotxtype for the animation on the y-axis relative to the object position type
The eighth parameter pivotyvalue the start position of the animation relative to the object's y-coordinate
Myanimation_scale =new scaleanimation (0.0f, 1.4f, 0.0f, 1.4f,
Animation.relative_to_self, 0.5f, Animation.relative_to_self, 0.5f);

③ Setting Animation duration

Java code
Myanimation_scale.setduration (700);
Set time duration to 700 milliseconds

Myanimation_scale.setduration (700);
Set time duration to 700 milliseconds

Translateanimation

①translateanimation Class object definitions

Java code
Private Alphaanimation Myanimation_alpha;

Private Alphaanimation Myanimation_alpha;

②translateanimation Class object constructs

Java code
Translateanimation (float Fromxdelta, float toxdelta,
Float Fromydelta, float toydelta)
The first argument fromxdelta the position at the start of the animation when the x-coordinate is moved
The second parameter toxdelta is the position of movement at the end of the animation at the X coordinate
The third parameter, Fromydelta, is the moving position on the y-coordinate at the start of the animation
The fourth parameter, Toydelta, is the moving position on the y-coordinate at the end of the animation

Translateanimation (float Fromxdelta, float toxdelta,
Float Fromydelta, float toydelta)
The first argument fromxdelta the position at the start of the animation when the x-coordinate is moved
The second parameter toxdelta is the position of movement at the end of the animation at the X coordinate
The third parameter, Fromydelta, is the moving position on the y-coordinate at the start of the animation
The fourth parameter, Toydelta, is the moving position on the y-coordinate at the end of the animation

③ Setting Animation duration

Java code
Myanimation_translate.setduration (2000);
Set time duration to 2000 milliseconds

Myanimation_translate.setduration (2000);
Set time duration to 2000 milliseconds

Rotateanimation
①rotateanimation Class object definitions

Java code
Private Alphaanimation Myanimation_alpha;

Private Alphaanimation Myanimation_alpha;

②rotateanimation Class object constructs

Java code
Rotateanimation (float fromdegrees, float todegrees,
int Pivotxtype, float pivotxvalue, int pivotytype, float pivotyvalue)
The first parameter fromdegrees is the angle of rotation at the beginning of the animation
The second parameter todegrees the angle to which the animation is rotated
The third parameter Pivotxtype for the animation on the x-axis relative to the object position type
The fourth parameter pivotxvalue the start position of the animation relative to the x-coordinate of the object
The fifth parameter Pivotxtype for the animation on the y-axis relative to the object position type
The sixth parameter pivotyvalue the start position of the animation relative to the object's y-coordinate
Myanimation_rotate=new rotateanimation (0.0f, +350.0f,
Animation.relative_to_self,0.5f,animation.relative_to_self, 0.5f);

Rotateanimation (float fromdegrees, float todegrees,
int Pivotxtype, float pivotxvalue, int pivotytype, float pivotyvalue)
The first parameter fromdegrees is the angle of rotation at the beginning of the animation
The second parameter todegrees the angle to which the animation is rotated
The third parameter Pivotxtype for the animation on the x-axis relative to the object position type
The fourth parameter pivotxvalue the start position of the animation relative to the x-coordinate of the object
The fifth parameter Pivotxtype for the animation on the y-axis relative to the object position type
The sixth parameter pivotyvalue the start position of the animation relative to the object's y-coordinate
Myanimation_rotate=new rotateanimation (0.0f, +350.0f,
Animation.relative_to_self,0.5f,animation.relative_to_self, 0.5f); ③ Setting Animation duration

Java code
Myanimation_rotate.setduration (3000);
Set time duration to 3000 milliseconds

Myanimation_rotate.setduration (3000);
Set time duration to 3000 milliseconds

Using animation effects in Java code
Use the method inherited from the View parent class Startanimation () to add an animation effect for view or subclass view, and so on.

Java code
public void Startanimation (Animation Animation)

Android Animation parsing--xml

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.