Use of Android-based animations

Source: Internet
Author: User

Animations can be divided into two categories: gradient (for example, fade-in and fade-out, rotation, movement, and scaling) and frame-by-frame, for example, a movie is usually displayed by multiple images at a certain interval.

Step 1 of using tweened animations:

1. Create an animationset object. The value of animationset = new animationset (Boolean B); // if the value of B is true, interpolator is shared.

2. Create corresponding animation objects (alphaanimation, rotateanimation, scaleanimation, and translateanimation) as needed)

3. Set the corresponding data for the animation object based on the needs of the software animation.

4. Add the animation object to the animationset object and use the addanimation method.

5. Use the control object to start executing the animationset

 

Step 2 of using tweened animations:

1. Create a folder named anim under the res folder

2. Create an XML file and add the set tag first. Modify the tag as follows:

<Set xmlns: Android = "http://schemas.android.com/apk/res/android"

Android: interpolator = "@ Android: anim/accelerate_interpolator"> // interpolator defines the animation Change Rate

</Set>

3. Add the rotate, Alpha, scale, or translate tag to the tag, for example:

<Alpha

Android: fromalphi = "0.1"

Android: toalpha = "1.0"

Android: Duration = "3000"/>

<Rotate

Android: fromdegrees = "0"

Android: todegrees = "+ 350"

Android: Required Tx = "50%"

Android: Ty = "50%"

Android: Duration = "3000"/>

--- Note --- there are three ways to set the value of Android: Release TX:

1. Android: Using Tx = "50" This method uses absolute location

2. Android: Export Tx = "50%", which is located relative to the control

3. Android: Export Tx = "50% P ".

4. Use animationutils in the code to load the XML file and generate the animation object, animationutils. loadanimation

 

Frame-by-frame: Usage

1. Create an XML file in RES/drawable to define the animation sequence of animations. The following is an example:

<Animation-list

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

Android: oneshot = "false">

<Item Android: drawable = "drawable/nv1"

Android: Duration = "500"/>

<Item Android: drawable = "drawable/nv2"

Android: Duration = "500"/>

<Item Android: drawable = "drawable/nv3"
Android: Duration = "500"/>

<Item Android: drawable = "drawable/nv4"

Android: Duration = "500"/>

</Animation-List>

2. imageview. setbackgroundresource ("ID of creating an XML file in RES/drawable ");

3. animationdrawable = (animationdrawable) imageview. getbackground ();

4. animationdrawable. Start ();

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.