Familiar with the process of Animation in Android 2 -- Transparency control Animation effect alpha

Source: Internet
Author: User

Transparency control animation effect alpha

XML definition

 

<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Alpha
Android: fromalphi = "0.1"
Android: toAlpha = "1.0"
Android: duration= "3000"
/>
</Set>

 

 

The toAlpha attribute is the transparency floating point type when the animation ends.

(0.0 indicates completely transparent. 1.0 indicates completely opaque)

The duration attribute is the animation duration (in milliseconds)

How does Java call animations defined in XML? The Code is as follows:

 

Public static Animation loadAnimation (Context context, int id)
// The first parameter Context is the Context of the program
// The second parameter id is the reference of the animated XML file.
MyAnimation = AnimationUtils. loadAnimation (this, R. anim. my_action );
// Use the static method loadAnimation () of the AnimationUtils class to load the animation XML file in XML

 

 

JavaCode Definition

AlphaAnimation

Private Animation myAnimation_Alpha; // defines the Animation.
MyAnimation_Alpha = new AlphaAnimation (0.1f, 1.0f); // initialize the animation object parameter 1. Transparency parameter 2. Transparency at animation end
MyAnimation_Alpha.setDuration (5000); // set the duration to 5000 milliseconds.
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.