ScaleAnimation for Android Animation

Source: Internet
Author: User

Android provides 4 Animation:
AlphaAnimation transparency animation effect
ScaleAnimation scaling animation effect
TranslateAnimation displacement animation effect
RotateAnimation rotation animation effect

This section describes the ScaleAnimation animation,
ScaleAnimation (float fromX, float toX, float fromY, float toY, int limit txtype, float limit txvalue, int limit tytype, float limit tyvalue)
Parameter description:Copy codeThe Code is as follows: the scaling size on the X coordinate at the start of the float fromX Animation
Scaling size on the X coordinate when float toX animation ends
Scaling size on Y coordinate at the start of float fromY Animation
Scaling size on Y coordinate when float toY animation ends
The type of the int extension txtype animation position on the X axis relative to the object
The starting position of the float pivotXValue animation relative to the X coordinate of the object
The type of the int tytytype animation position relative to the object on the Y axis.
The starting position of the float tyvalue animation relative to the Y coordinate of the object

Code:Copy codeThe Code is as follows: public class MainActivity extends Activity {
ImageView image;
Button start;
Button cancel;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
Image = (ImageView) findViewById (R. id. main_img );
Start = (Button) findViewById (R. id. main_start );
Cancel = (Button) findViewById (R. id. main_cancel );
/** Set scaling animation */
Final ScaleAnimation animation = new ScaleAnimation (0.0f, 1.4f, 0.0f, 1.4f,
Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f );
Animation. setDuration (2000); // sets the animation duration.
/** Common methods */
// Animation. setRepeatCount (int repeatCount); // you can specify the number of repetitions.
// Animation. setFillAfter (boolean); // whether the animation is in the running state after execution
// Animation. setStartOffset (long startOffset); // the waiting time before execution
Start. setOnClickListener (new OnClickListener (){
Public void onClick (View arg0 ){
Image. setAnimation (animation );
/** Start animation */
Animation. startNow ();
}
});
Cancel. setOnClickListener (new OnClickListener (){
Public void onClick (View v ){
/** End animation */
Animation. cancel ();
}
});
}
}

Effect:

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.