Android Animation Properties Animation

Source: Internet
Author: User

Animation

In the Android program often use animation effect, and animation effect is mainly animation to achieve, the API gives the explanation:

  

It contains 4 animation effects

Alphaanimation Gradient Transparency

Rotateanimation Screen Rotation

Scaleanimation Gradient Size scaling

Translateanimation Position Movement

But if you want to combine these animation effects, you need a class Animationset animation set .

Here's a simple explanation for these classes:

 examples of alphaanimation :

1     New Alphaanimation (0.1f, 1.0f); 2             Alpha.setduration (+); 3             Image.startanimation (Alpha);

The transparency changes from 0.1f to 1.0f, and the event required for the change is 2s;

  examples of rotateanimation :

1 New rotateanimation (0f, 360f); 2             Rotate.setduration (+); 3             Image.startanimation (rotate);

Rotates from 0 degrees to 360 degrees, duration is 2S

  Examples of scaleanimation:

New Scaleanimation (0.1f, 1.0f, 0.1f, 1.0f);            Scale.setduration (+);            Image.startanimation (scale);

The length on the x-axis changes from 0.1 to 1.0f (view original width)

The length on the y-axis changes from 0.1 to 1.0f (view original length)

  Examples of translateanimation:

 1  Animation translate =  New   Translateanimation (  2  animation.relative_to_self, 1.0f 3  animation.relative_to_self, 0.0f 4  animation.relative_to_self, 1.0f 5  animation.relative_to_self, 0.0f 6  translate.setduration (2000) ; 

  Examples of Animationset:

Animation rotate1 =Newrotateanimation (0f, 360f); Animation translate1=Newtranslateanimation (animation.relative_to_self,1.0f, Animation.relative_to_self,0.0f, Animation.relative_to_self,1.0f, Animation.relative_to_self,0.0f); Animationset Set=NewAnimationset (true);            Set.addanimation (ROTATE1);            Set.addanimation (TRANSLATE1); Set.setduration (2000); Image.startanimation (set);

In addition to adding animations to the code, you can also define the animation directly in the XML file, which is OK on the direct call, for example:

1     <?XML version= "1.0" encoding= "Utf-8"?>  2     <Setxmlns:android= "Http://schemas.android.com/apk/res/android">  3         <Alpha4             Android:fromalpha= "0.1"  5 Android:toalpha= "1.0"  6 android:duration= "$"  7         />  8     </Set>  

Program code Effects:

Each button corresponds to a different animation

  

  

Code download: Download

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.