Android 18th-day notes-simple animation, Android 18th --

Source: Internet
Author: User

Android 18th-day notes-simple animation, Android 18th --

Title: animation Animation 1. Compensation Animation 2. Translation
FromXType: where does the fromXValue start from? 0 indicates the current position toXType, where is the type toXValue, and where is the coordinate fromYType? Where does fromYValue start from, 0 indicates the current position from toYType to the type from toYValue to the coordinates
TranslateAnimation translate = new TranslateAnimation (Animation. RELATIVE_TO_SELF,-2, Animation. RELATIVE_TO_SELF, 2, Animation. RELATIVE_TO_SELF, 0, Animation. RELATIVE_TO_SELF, 1); // sets the display time to translate. setDuration (3000); // The playback resource is an infinite loop of translate. setRepeatCount (Animation. INFINITE); // playback mode. The playback mode is reversed. After the playback is completed, the translate is reversed. setRepeatMode (Animation. REVERSE); // which component is playing, set imageView. setAnimation (translate); // start playing translate. start ();

 

3. Rotate
/** FromDegrees, from which point of view is 0 from the current toDegrees, 270 degrees 1_txtype, X center type * Animation. RELATIVE_TO_SELF implements txvalue. the center point value of 0.5 indicates that the image is set to * tytype, And the Y center type is Animation. RELATIVE_TO_SELF * polictyvalue 0.5f */RotateAnimation rotate = new RotateAnimation (0,360, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 3); // The playback display time rotate. setDuration (5000); rotate. setRepeatCount (Animation. INFINITE); rotate. setRepeatMode (Animation. RESTART); imageView. setAnimation (rotate); rotate. start ();

 

4. Zoom
/** FromX, toX, starting from the coordinate address to the coordinate, 0, indicating the current fromY, toY, * rotate txtype, center of rotation * rotate txvalue, type, skip tytype, specified tyvalue */ScaleAnimation scale = new ScaleAnimation (1, 2, 1,-2, Animation. RELATIVE_TO_SELF,-2, Animation. RELATIVE_TO_SELF, 3); // scale the playback display time. setDuration (5000); scale. setRepeatCount (Animation. INFINITE); scale. setRepeatMode (Animation. RESTART); imageView. setAnimation (scale); scale. start ();

 

5. Transparency
/** FromAlpha, starting from what transparency * toAlpha to what transparency ends */AlphaAnimation alpha = new AlphaAnimation (1, 0); // The playback display time alpha. setDuration (1, 2000); alpha. setRepeatCount (Animation. INFINITE); alpha. setRepeatMode (Animation. REVERSE); imageView. setAnimation (alpha); alpha. start ();}

 

6. Set
Is to create
AnimationSet set = new AnimationSet();set.addAnimation(scale);    set.addAnimation(rotate);    set.addAnimation(translate);    set.start();

 

You can play multiple animations.
7. XML configuration
Create an anim file directory under the res/directory
<! -- If the translation value is a number, it indicates the absolute value. If it is a percentage, it indicates that it is a multiple of its own width and height. If it is a percentage Plus p, it indicates that it is a multiple of the width and height of its parent element --> <? Xml version = "1.0" encoding = "UTF-8"?> <Set xmlns: android = "http://schemas.android.com/apk/res/android"> <translate android: fromXDelta = "200%" android: toXDelta = "200%" android: fromYDelta = "-100%" android: toYDelta = "200%" android: duration = "4000" android: repeatCount = "infinite" android: repeatMode = "reverse"/> <rotate android: fromDegrees = "0" android: toDegrees = "360" android: toYScale = "0.0" android: Short Tx = "50%" android: Short ty = "50%" android: duration = "4000" android: repeatCount = "infinite" android: repeatMode = "reverse"/> </set>

 

Load Using the AnimationUtils. load Method

Animation animation = AnimationUtils.loadAnimation(this, R.anim.animation_set);    imageView.startAnimation(animation);

 

8. Property Animation

Generally, code control is used.

/*** Horizontal ** @ param v */public void translate (View v) {/*** parameter 1: Who will play this animation? parameter 2: property name to change the direction of x. Parameter 3: animation execution value */ObjectAnimator objectAnimatrX = ObjectAnimator. ofFloat (imageView, "translationX",-50, 50); ObjectAnimator objectAnimatrY = ObjectAnimator. ofFloat (imageView, "translationY", 0, 60); objectAnimatrX. setDuration (2000); objectAnimatrX. setRepeatCount (ObjectAnimator. INFINITE); objectAnimatrX. setRepeatMode (ObjectAnimator. REVERSE); objectAnimatrX. start ();}/*** conversion ** @ param v */public void rotate (View v) {ObjectAnimator rotateX = ObjectAnimator. ofFloat (imageView, "rotationX", 0,360); ObjectAnimator rotateY = ObjectAnimator. ofFloat (imageView, "rotationY", 0,360); rotateX. setduration( 3000); rotateX. setRepeatMode (Animation. REVERSE); // rotateX. setRepeatCount (Animation. INFINITE); rotateY. setDuration (3000); rotateY. setRepeatMode (Animation. REVERSE); // rotateY. setRepeatCount (Animation. INFINITE); AnimatorSet set = new AnimatorSet (); set. playSequentially (rotateX, rotateY); set. start ();}/*** bloom ** @ param v */public void scale (View v) {ObjectAnimator scaleX = ObjectAnimator. ofFloat (imageView, "scaleX", 2.0f, 5f); ObjectAnimator scaleY = ObjectAnimator. ofFloat (imageView, "scaleY", 2.0f, 5f); scaleX. setDuration (3000); scaleX. setRepeatMode (Animation. REVERSE); scaleX. setRepeatCount (Animation. INFINITE); scaleY. setDuration (3000); scaleY. setRepeatMode (Animation. REVERSE); scaleY. setRepeatCount (Animation. INFINITE); AnimatorSet set = new AnimatorSet (); set. playTogether (scaleX, scaleY); set. start ();}/*** transparent ** @ param v */public void alpha (View v) {ObjectAnimator alpha = ObjectAnimator. ofFloat (imageView, "alpha", 1.0f, 0f); alpha. setDuration (1, 3000); alpha. setRepeatMode (Animation. REVERSE); alpha. setRepeatCount (Animation. INFINITE); alpha. start ();}/*** set ** @ param v */public void set (View v) {/*** parameter 1: Who will play the animation? parameter 2: property name to change the direction of x. Parameter 3: animation execution value */ObjectAnimator objectAnimatrX = ObjectAnimator. ofFloat (imageView, "translationX",-50,100); ObjectAnimator objectAnimatrY = ObjectAnimator. ofFloat (imageView, "translationY",-70,100); objectAnimatrX. setDuration (2000); // objectAnimatrX. setRepeatCount (ObjectAnimator. INFINITE); objectAnimatrX. setRepeatMode (ObjectAnimator. REVERSE); objectAnimatrY. setDuration (2000); // objectAnimatrY. setRepeatCount (ObjectAnimator. INFINITE); objectAnimatrY. setRepeatMode (ObjectAnimator. REVERSE); AnimatorSet set = new AnimatorSet (); // set. playTogether (objectAnimatrX, objectAnimatrY); set. playSequentially (objectAnimatrX, objectAnimatrY); set. start ();}

 

If you need to use XML control, you can create an animator under res \. Create an XML file in this directory.

AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext,R.anim.property_animator);set.setTarget(myObject);set.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.