Android realizes the fade and fade animation effect in the game _android

Source: Internet
Author: User

1 to realize fade animation

Implementing in a program can be done in the following ways

View view = new view (context);//Animation view
alphaanimation AA = new Alphaanimation (1.0f, 0.0f);//Create a Alphaanimation object , the gradient
sets the duration Aa.setfillafter (true) from the 1->0 aa.setduration (1500);
//sets the last state of the view, because it is from 1->0, So the final is the vanishing state (and finally the view is not visible)
viewstartanimation (AA);/Start animation

Of course, the configuration file can also be implemented

First create a new Anim folder in the Res directory, and then create a new XML file under Anim folder Gradually.xml

The XML file primarily defines how the gradient is implemented

<?xml version= "1.0" encoding= "Utf-8"?> <set xmlns:android= 
"http://schemas.android.com/apk/res/" Android "> 
<alpha 
android:fromalpha=" 0.0 " 
android:toalpha=" 1.0 " 
android:duration=" 2000 " 
/> 

Alpha represents transparency, 0.0 is completely transparent, 1.0 is completely opaque, duration refers to excess time

Animation Animation = animationutils.loadanimation (context, r.anim.gradually);
View.setfillafter (TRUE)//keep the last gradient state
view.startanimation (animation);//Start animation

2 realize the effect of fading

View view = new view (context);//Animation view
alphaanimation AA = new Alphaanimation (0.0f, 1.0f);//Create a Alphaanimation object , the gradient
sets the duration Aa.setfillafter (true) from the 1->0 aa.setduration (1500);
//sets the final animation effect, which is the display status (the last view can be seen)
Viewstartanimation (AA);//Start animation

The actual implementation of the configuration file is similar to the above.

The above is a small set of Android to introduce the realization of the game in the fade and fade animation effect of all content, I hope to help everyone, if you have any questions welcome to my message, small series will promptly reply to everyone!

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.