Basics of Android Animation

Source: Internet
Author: User


Frames-per-frame animation
/**
* 1. Add a single photo
* 2. Generate movie.xml entire picture
* 3. Use the image in the code Movie.xml
*/
iv= (ImageView) Findviewbyid (R.ID.IV);
Iv.setimageresource (R.drawable.movie);//load six photos for IV
Animationdrawable ad= (animationdrawable) iv.getdrawable ();//Get pictures to animated pictures
Ad.start ();

Displaymetrics dm = new Displaymetrics ();
GetWindow (). Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);
int width = dm.widthpixels;//to get screen width

Motion Tweens, panning
1. Write directly through the code
Animation translate=new translateanimation (0, width, 0, 0);
Translate.setduration (2000);
Translate.setfillafter (TRUE);//After the animation is complete, stay in the position

Translate.setrepeatcount (2);//Repeat 2 times
Translate.setstartoffset (1000);//wait 1 seconds to move again

Iv.startanimation (translate);

2. Calling the XML file
Animation translate=animationutils.loadanimation (this, r.anim.push_to_right);
Iv.startanimation (translate);
Iv.setanimation (translate);

Animated Listener Events
Translate.setanimationlistener (New Animationlistener () {

@Override
public void Onanimationstart (Animation Animation) {

}

@Override
public void Onanimationrepeat (Animation Animation) {

}

@Override
public void Onanimationend (Animation Animation) {
Intent intent=new Intent (mainactivity.this,secondaty.class);
StartActivity (Intent);
Finish ();

}
});

}

Rotate animation
Angle from 0 to 360,pivotxtype who's X value (interface of? The picture itself) Pivotytype
Animation rotator = new Rotateanimation (0, 360,
Rotateanimation.relative_to_self, 0.5f,
Rotateanimation.relative_to_self, 0.5f);
Rotator.setduration (3000);
Rotator.setfillafter (TRUE);
Iv.startanimation (rotator);

Gradient
Animation alpha = new Alphaanimation (0, 0.9f);//from unseen to see 90%
Alpha.setduration (3000);
Alpha.setfillafter (TRUE);
Iv.startanimation (Alpha);

Stretch
FromX, ToX, FromY, toy translation Animation four parameters, x-axis telescopic size, y-axis telescopic size
Scaleanimation.relative_to_self, the 3f//x axis coordinates are 3 times times the width of your own picture.
Animation scale = new Scaleanimation (0, 0.3f, 0, 0.5f,
Scaleanimation.relative_to_self, 3f,
Scaleanimation.relative_to_self, 3f);
Scale.setduration (3000);
Scale.setfillafter (TRUE);
Iv.startanimation (scale);

Basics of Android Animation

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.