Android Zoom Animation Core method
publicvoidstartAnimation(Animation animation)
- To perform animations, parameters can be objects of various animations, animation polymorphism, or composite animations, which can be later.
4 Method of parameter construction
/** * 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;}
Usage
publicvoid scale(View view) { // 创建缩放的动画对象 new ScaleAnimation(0f,1.0f,0f,1.0f); // 设置动画播放的时间 sa.setDuration(1000); // 开始播放动画 iv.startAnimation(sa);}
Effect
In the upper left corner of the picture, never, zoom to the original size of the picture.
6 Method of parameter construction
/** * 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 construction of the four parameters are set by default for both parameters 0, so it is in the upper left corner of the picture to start scaling
Usage
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 Method of parameter construction
/** * 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 (); }
Usage
// 创建缩放的动画对象new ScaleAnimation(0f1.0f0f1.0f0.5f0.5f);// 设置动画播放的时间sa.setDuration(1000);// 开始播放动画iv.startAnimation(sa);
- Compared with the above 6 parameters, only the 5th and 7th parameters, respectively, set their type, the note has been explained, you can set Animation.absolute, Animation.relative_to_self, Animation.relative_to_parent type
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 how many times the animation repeats
/** * 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 of animation repeat playback
/** * 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);
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Zoom Animation