Android Zoom Animation

Source: Internet
Author: User

Android Zoom Animation Core method
publicvoidstartAnimation(Animation animation)
    • Run animation, the number of parameters can be a variety of animation objects, animation polymorphism. It can also be a combination animation, which will be available later.
4 Number of parameters construction method
/** * Constructor toUse when building a scaleanimation fromCode * * @param FromX Horizontal Scaling factor toApply at  theStart of  theAnimation * @param ToX Horizontal Scaling factor toApply at  the End  of  theAnimation * @param FromY Vertical scaling factor toApply at  theStart of  theAnimation * @param ToY Vertical scaling factor toApply at  the End  of  theAnimation */public scaleanimation (float FromX, float toX, float fromY, float toY) {mresources = null;    MFROMX = FromX;    Mtox = ToX;    mfromy = FromY;    Mtoy = ToY; Mpivotx =0; Mpivoty =0;}

How to use

publicvoid scale(View view) {    // 创建缩放的动画对象    new ScaleAnimation(0f,1.0f,0f,1.0f);    // 设置动画播放的时间    sa.setDuration(1000);    // 開始播放动画    iv.startAnimation(sa);}

Effect

Take the top left corner of the picture as the Origin point. No, zoom to the original size of the picture

6 Number of parameters construction method
/** * Constructor toUse when building a scaleanimation fromCode * * @param FromX Horizontal Scaling factor toApply at  theStart of  theAnimation * @param ToX Horizontal Scaling factor toApply at  the End  of  theAnimation * @param FromY Vertical scaling factor toApply at  theStart of  theAnimation * @param ToY Vertical scaling factor toApply at  the End  of  theAnimation * @param pivotx the X coordinate of  thePoint Aboutwhich theObject isBeing scaled, specified asAn absolute Number where 0  is  theLeft edge. (This point remains fixed while  theObject changes size.) * @param pivoty the Y coordinate of  thePoint Aboutwhich theObject isBeing scaled, specified asAn absolute Number where 0  is  theTop edge. (This point remains fixed while  theObject changes size.) */Public Scaleanimation (float FromX, float toX, float fromY, float toY, float pivotx, float pivoty) {mresources       = NULL;       MFROMX = FromX;       Mtox = ToX;       mfromy = FromY;       Mtoy = ToY;       Mpivotxtype = ABSOLUTE;       Mpivotytype = ABSOLUTE;       Mpivotxvalue = Pivotx;       Mpivotyvalue = Pivoty;   Initializepivotpoint (); }
    • The first 4 parameters are the same as above, the last two parameters are the origin of the image scaling, the four-parameter construction defaults to set the two parameters to 0, so it is in the upper left corner of the picture to start zooming

How to use

new ScaleAnimation(0f1.0f0f1.0f22);// 设置动画播放的时间sa.setDuration(1000);// 開始播放动画iv.startAnimation(sa);

Effect

Take the center of the picture as the origin, never zoom in to the original size of the picture

8 Number of parameters construction method
/** * Constructor toUse when building a scaleanimation fromCode * * @param FromX Horizontal Scaling factor toApply at  theStart of  theAnimation * @param ToX Horizontal Scaling factor toApply at  the End  of  theAnimation * @param FromY Vertical scaling factor toApply at  theStart of  theAnimation * @param ToY Vertical scaling factor toApply at  the End  of  theAnimation * @param pivotxtype Specifies how Pivotxvalue should is interpreted. One ofAnimation.absolute, Animation.relative_to_self,orAnimation.relative_to_parent. * @param pivotxvalue the X coordinate of  thePoint Aboutwhich theObject isBeing scaled, specified asAn absolute Number where 0  is  theLeft edge. (This point remains fixed while  theObject changes size.) This value can either is an absolute Number ifPivotxtype isABSOLUTE,orA percentage (where 1.0  is  -%) otherwise. * @param pivotytype Specifies how Pivotyvalue should is interpreted. One ofAnimation.absolute, Animation.relative_to_self,orAnimation.relative_to_parent. * @param pivotyvalue the Y coordinate of  thePoint Aboutwhich theObject isBeing scaled, specified asAn absolute Number where 0  is  theTop edge. (This point remains fixed while  theObject changes size.) This value can either is an absolute Number ifPivotytype isABSOLUTE,orA percentage (where 1.0  is  -%) otherwise. */Public Scaleanimation (float FromX, float toX, float fromY, float toY, int pivotxtype, float pivotxvalue, int pivotyty       PE, float pivotyvalue) {mresources = null;       MFROMX = FromX;       Mtox = ToX;       mfromy = FromY;       Mtoy = ToY;       Mpivotxvalue = Pivotxvalue;       Mpivotxtype = Pivotxtype;       Mpivotyvalue = Pivotyvalue;       Mpivotytype = Pivotytype;   Initializepivotpoint (); }

How to use

// 创建缩放的动画对象new ScaleAnimation(0f1.0f0f1.0f0.5f0.5f);// 设置动画播放的时间sa.setDuration(1000);// 開始播放动画iv.startAnimation(sa);
    • Compared with the above 6 parameters, it is only the 5th and 7th, respectively, setting their type, and the gaze is already explained. Ability to set Animation.absolute, animation.relative_to_self, animation.relative_to_parent types

Effect

The effect is the same as above, with the center of the image as the origin, never zoomed in to the original size of the picture.

To set the number of times the animation plays repeatedly
/** * Sets how many Times  theAnimation should be repeated. If the Repeat*Count  is 0, theAnimation isNever repeated. If the Repeat Count  is*Greater than 0 or{@link#INFINITE}, the repeat mode would be taken* intoAccount. TheRepeat Count  is 0  byDefault. * * @param repeatcount the  Number  of  Times  theAnimation should be repeated * @attrrefAndroid. R.styleable#Animation_repeatCount*/public void Setrepeatcount (int repeatcount) {if(RepeatCount <0) {repeatcount = INFINITE; } Mrepeatcount = RepeatCount;}

Use

sa.setRepeatCount(2);
To set the mode for animation to play repeatedly
/** * Defines what this animation should do when it reaches the end. This * setting is applied only when the repeat count is either greater than * 0 or {@link #INFINITE}. Defaults to {@link #RESTART}.  * * @param repeatMode {@link #RESTART} or {@link #REVERSE} * @attr ref android.R.styleable#Animation_repeatMode */publicvoidsetRepeatMode(int repeatMode) {    mRepeatMode = repeatMode;}

Use

sa.setRepeatMode(ScaleAnimation.REVERSE);

Android Zoom Animation

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.