How to Set animation effects in XML format in Android

Source: Internet
Author: User

Statement

You are welcome to repost, but please keep the original source of the article :)

Focus: http://www.focuser.org

Link: http://www.focuser.org /? P = 267


In
Android
Medium,
Animation
Animation effects can be implemented in two ways, one is
Tweened
Animation
Gradient animation, the other is
Frame
By Frame Animation
Screen conversion animation.

Tweened Animation
There are two types of gradient Animation:

1. Alpha


Gradient transparency animation effect

2. Scale


Gradient scaling animation effect

Frame by frame animation
There are two types of screen conversion Animation:

1. Translate


Animation Effect

2. Rotate


Animation effects of screen transfer and Rotation

In
Res
Create a folder
Anim
And create
Animation. xml
File:

<? XML version = "1.0"
Encoding = "UTF-8"?>

<Set

Xmlns: Android = "http://schemas.android.com/apk/res/android">


<Translate


Android: fromxdelta = "0"
//
When the animation is set to start
X
Coordinates


Android: toxdelta = "-100% P"
//
Set the animation End Time
X
Coordinates


Android: duration= "300"
//
Set the animation duration
300
Millisecond


>


</Translate>


<Alpha


Android: fromalphi = "1.0"
//
Sets the transparency at the beginning of the animation.

1.0
Indicates opacity


Android: toalpha = "0.0"
//
Sets the transparency at the beginning of the animation.

0.0
Completely transparent


Android: duration= "300"
//
Set the animation duration
300
Millisecond


/>


<Scale



Android: interpolator ="
//
Set the animation Reader

@ Android: anim/accelerate_decelerate_interpolator"



Android: fromxscale = "0.0"
//
When the animation is set to start
X
Scaling length on coordinates



Android: toxscale = "1.4"
//
Set the animation End Time
X
Scaling length on coordinates



Android: fromyscale = "0.0"
//
When the animation is set to start
Y
Scaling length on coordinates



Android: toyscale = "1.4"
//
When the animation is set to start
Y
Scaling length on coordinates



Android: Required Tx = "50%"
//
Set the animation to
X
Coordinates



Android: Ty = "50%"
//
Set the animation to
Y
Coordinates



Android: fillafter = "false"
//
This animation is used before the animation ends.



Android: Duration = "700 "//
Set the animation duration

/>


 
<Rotate



Android: interpolator =
//
Set the animation Reader

"@ Android: anim/accelerate_decelerate_interpolator"



Android: fromdegrees = "0"
//
Set the animation start angle



Android: todegrees = "+ 350"
//
Sets the rotation angle at the animation end.



Android: Required Tx = "50%"
//
Set the animation to
X
Coordinates



Android: Ty = "50%"
//
Set the animation to
Y
Coordinates



Android: duration= "3000"
//
Set the animation duration



/>

</Set>

Exploitation
Animationutils. loadanimation
Load an animation

Animation animation;

Animation = animationutils. loadanimation (this,
R. anim. animation );

Then, you can use
Startanimation ()
Method.

//
Compile an animation object and obtain the Custom Animation style.

Animation = animationutils. loadanimation (this,
R. anim. animation );



Spinner. setontouchlistener (new Spinner. ontouchlistener (){



@ Override


Public
Boolean ontouch (view V, motionevent event ){


//
Todo auto-generated method stub


//
Run the animation
Animation


V. startanimation (animation );


//
Set
Spinner
Sets the visibility to invisible.


V. setvisibility (view. Invisible );


Return
False;


}


});

Link: http://www.focuser.org /? P = 267

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.