Use of Animationset

Source: Internet
Author: User

use of animations (3)

1 How to use animationset

What is Animationset

1 Animationset is a subclass of animation

21 Animationset contains a series of animation

3 set some common properties of animation (such as startoffset,duration, etc.) for Animationset, which can be included in animation inheritance in Animationset

Use steps : (similar to the example in 1 only has 2 animation effects)

Java code
    1. Animationset Animationset = new Animationset (ture);
    2. Alpahaanimation alpha = new Alphaanimation (...);
    3. Rotateanimation rotate = new Rotateanimation (...);
    4. Animationset.addanimation (Alpha);
    5. Animationset.addanimaion (rotate);
    6. Animationset.setduration (+);
    7. Animationset.setstartoffset (+);
    8. Imageview.startanimation (Animationset);
Animationset animationset = new Animationset (ture); Alpahaanimation alpha = new Alphaanimation (...); Rotateanimation rotate = new rotateanimation (...); Animationset.addanimation (Alpha); animationset.addanimaion (rotate); animationset.setduration (2000); Animationset.setstartoffset (+); imageview.startanimation (Animationset);

2 How to use Interpolator

Interpolator defines the rate of animation change and defines the following interpolator in the animations framework

Acceleratedecelerateinterpolator: Velocity changes slowly at the beginning and end of the animation, accelerating in the middle

Accelerateinterpolator: At the beginning of the animation, the rate changes slowly, and then accelerates

Cycleinterpolator: Animation loop plays a specific number of times, rate changes along the sine curve

Decelerateinterpolator: At the beginning of the animation, the rate changes slower, then slows down

Linearinterpolator: Change at a uniform rate

Set the Android:interpolator= "@android: Anim/accelerate_interpolator" in the set tag

And then there's a android:shareinterpolator= "true" from the name you can see that this is set for all the animations in set Interpolator

If you want to set it individually, set Shareinterpolator to False and define the Interpolator separately for each animation

The above is set in XML , if you want to set in code

Animationset.setinterpolator (New Accelerateinterpolator ()); (can also be set separately)

Note that there is a Boolean parameter in the Animationset constructor, which is the Shareinterpolator setting

3 How to use Frame-by-frame animations

1 Create an XML file in res/drawable that defines the animation animation play sequence Anim_nv.xml

XML code
  1. <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:oneshot="false">
  3. <item android:drawable="@drawable/nv1"
  4. android:duration=" /> "
  5. <item android:drawable="@drawable/nv2"
  6. android:duration=" /> "
  7. <item android:drawable="@drawable/nv3"
  8. android:duration=" /> "
  9. <item android:drawable="@drawable/nv4"
  10. android:duration=" /> "
  11. </animation-list>
<animation-list xmlns:android= "Http://schemas.android.com/apk/res/android" android:oneshot= "false" >< Item android:drawable= "@drawable/nv1" android:duration= "/><item android:drawable=" @drawable/nv2 "Android :d uration= "/><item android:drawable=" @drawable/nv3 "android:duration="/><item android: drawable= "@drawable/nv4" android:duration= "/></animation-list>

2 Setting a background resource for ImageView

Java code
    1. Imageview.setbackgroundresource (R.drawable.anim_nv);
Imageview.setbackgroundresource (R.drawable.anim_nv);

3 Get animationdrawable through ImageView

Java code
    1. Animationdrawable animationdrawable = (animationdrawable) imageview.getbackground ();
Animationdrawable animationdrawable = (animationdrawable) imageview.getbackground ();

3 Performing animations

Java code
    1. Animationdrawable.start ();
Animationdrawable.start ();

Use of Animationset

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.