Android code implementation scaleanimation

Source: Internet
Author: User
Tags repetition
Package com.yangguangfu.cn;

Import Android. App. activity;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. View. animation. animation;
Import Android. View. animation. animation. animationlistener;
Import Android. View. animation. scaleanimation;
Import Android. widget. imageview;

Public class scaleanimationdemoactivity extends activity implements
Onclicklistener {

Private imageview top_left;
Private imageview top_right;
Private imageview bottom_left;
Private imageview bottom_right;
Private imageview center;

/** called when the activity is first created. */
@ override
Public void oncreate (bundle savedinstancestate) {// use findviewbyid,
super. oncreate (savedinstancestate); // serves as the user interface
setcontentview (R. layout. second);

// obtain the view object in the UI interface
// after obtaining the view object, convert it to the actual object
top_left = (imageview) findviewbyid (R. id. top_left);
top_right = (imageview) findviewbyid (R. id. top_right);
bottom_left = (imageview) findviewbyid (R. id. bottom_left);
bottom_right = (imageview) findviewbyid (R. id. bottom_right);
center = (imageview) findviewbyid (R. id. center);
top_left.setonclicklistener (this);
top_right.setonclicklistener (this);
Publish (this);
bottom_right.setonclicklistener (this);
center. setonclicklistener (this);

}

@ Override
Public void onclick (view v ){
Switch (V. GETID ()){
Case R. Id. top_left:
Topleftscaleanimation (v );
Break;
Case R. Id. top_right:
Toprightscaleanimation (v );
Break;
Case R. Id. bottom_left:
Bottomliftscaleanimation (v );
Break;
Case R. Id. bottom_right:
Bottomrightscaleanimation (v );
Break;
Case R. Id. Center:
Centerscaleanimation (v );

Break;
}
}

Private animation topleftanimation;
Private Boolean istopleft = false;

Private void topleftscaleanimation (final view v ){

If (! Istopleft ){

Topleftanimation = new scaleanimation (1.0f, 4.0f, 1.0f, 4.0f,
Animation. relative_to_self, 0.0f,
Animation. relative_to_self, 0.0f );

Istopleft = true;

} Else {
Topleftanimation = new scaleanimation (4.0f, 1.0f, 4.0f, 1.0f,
Animation. relative_to_self, 0.0f,
Animation. relative_to_self, 0.0f );
Istopleft = false;

}

// Execution time from animation start to end (1000 = 1 second)
Topleftanimation. setduration (2000 );

// Number of animation repetitions (-1 indicates repetition)
// Am. setrepeatcount (1 );
Topleftanimation. setanimationlistener (New animationlistener (){

@ Override
Public void onanimationstart (animation ){
// Todo auto-generated method stub

}

@ Override
Public void onanimationrepeat (animation ){
// Todo auto-generated method stub

}

@ Override
Public void onanimationend (animation ){
Top_left.setenabled (true );

}
});
Topleftanimation. setfillafter (true );
// Picture configuration Animation
Top_left.setanimation (topleftanimation );

// Help ();
// Handler. sendemptymessagedelayed (tophand, 2000 );
// Top_left.setlayoutparams (LP );
// Animation starts
Topleftanimation. startnow ();

Top_left.setenabled (false );
}

Private Static final int tophand = 6;

Private Boolean isbottomlift = false;
Animation bottomliftscaleanimation = NULL;

Private void bottomliftscaleanimation (view v ){

If (! Isbottomlift ){
Bottomliftscaleanimation = new scaleanimation (1.0f, 4.0f, 1.0f,
4.0f, animation. relative_to_self, 0f,
Animation. relative_to_self, 1.0f );
Isbottomlift = true;
} Else {
Bottomliftscaleanimation = new scaleanimation (4.0f, 1.0f, 4.0f,
1.0f, animation. relative_to_self, 0f,
Animation. relative_to_self, 1.0f );
Isbottomlift = false;
}

// Execution time from animation start to end (1000 = 1 second)
Bottomliftscaleanimation. setduration (2000 );

// Number of animation repetitions (-1 indicates repetition)
// Bottomliftscaleanimation. setrepeatcount (-1 );
Bottomliftscaleanimation. setfillafter (true );
// Picture configuration Animation
Bottom_left.setanimation (bottomliftscaleanimation );
Bottomliftscaleanimation. setanimationlistener (New animationlistener (){

@ Override
Public void onanimationstart (animation ){
// Todo auto-generated method stub

}

@ Override
Public void onanimationrepeat (animation ){
// Todo auto-generated method stub

}

@ Override
Public void onanimationend (animation ){
Bottom_left.setenabled (true );
}
});
// Animation starts
Bottomliftscaleanimation. startnow ();
Bottom_left.setenabled (false );
}

Private Boolean isbottomri.pdf = false;
Animation bottomrightscaleanimation;

Private void bottomrightscaleanimation (view v ){
If (! Isbottomrigth ){
Bottomrightscaleanimation = new scaleanimation (1.0f, 4.0f, 1.0f,
4.0f, animation. relative_to_self, 1.0f,
Animation. relative_to_self, 1.0f );
Isbottomrigth = true;
} Else {
Bottomrightscaleanimation = new scaleanimation (4.0f, 1.0f, 4.0f,
1.0f, animation. relative_to_self, 1.0f,
Animation. relative_to_self, 1.0f );
Isbottomrigth = false;
}
// Execution time from animation start to end (1000 = 1 second)
Bottomrightscaleanimation. setduration (2000 );
Bottomrightscaleanimation. setanimationlistener (New animationlistener (){

@ Override
Public void onanimationstart (animation ){
// Todo auto-generated method stub

}

@ Override
Public void onanimationrepeat (animation ){
// Todo auto-generated method stub

}

@ Override
Public void onanimationend (animation ){
// Todo auto-generated method stub
Bottom_right.setenabled (true );

}
});

// Number of animation repetitions (-1 indicates repetition)
// Bottomrightscaleanimation. setrepeatcount (-1 );
Bottomrightscaleanimation. setfillafter (true );
// Picture configuration Animation
Bottom_right.setanimation (bottomrightscaleanimation );

// Animation starts
Bottomrightscaleanimation. startnow ();

Bottom_right.setenabled (false );
}

Private animation toprightscaleanimation;
Private Boolean istopright = false;

private void toprightscaleanimation (view v) {
If (! Istopright) {
toprightscaleanimation = new scaleanimation (1.0f, 4.0f, 1.0f, 4.0f,
animation. relative_to_self, 1.0f,
animation. relative_to_self, 0.0f);
istopright = true;

} Else {
Toprightscaleanimation = new scaleanimation (4.0f, 1.0f, 4.0f, 1.0f,
Animation. relative_to_self, 1.0f,
Animation. relative_to_self, 0.0f );
Istopright = false;
}
Toprightscaleanimation. setduration (2000); Container Freight

// Number of animation repetitions (-1 indicates repetition)
// Toprightscaleanimation. setrepeatcount (-1 );

// Picture configuration Animation
Top_right.setanimation (toprightscaleanimation );
Toprightscaleanimation. setanimationlistener (New animationlistener (){

@ Override
Public void onanimationstart (animation ){
// Todo auto-generated method stub

}

@ Override
Public void onanimationrepeat (animation ){
// Todo auto-generated method stub

}

@ Override
Public void onanimationend (animation ){
Top_right.setenabled (true );

}
});

// Animation starts
Toprightscaleanimation. startnow ();
Toprightscaleanimation. setfillafter (true );

Top_right.setenabled (false );
}

Private Boolean iscenter = false;
Animation centerscaleanimation;

Private void centerscaleanimation (view v ){
If (! Iscenter ){
Centerscaleanimation = new scaleanimation (1.0f, 4.0f, 1.0f, 4.0f,
Animation. relative_to_self, 0.5f,
Animation. relative_to_self, 0.5f );
Iscenter = true;
} Else {
Centerscaleanimation = new scaleanimation (4.0f, 1.0f, 4.0f, 1.0f,
Animation. relative_to_self, 0.5f,
Animation. relative_to_self, 0.5f );
Iscenter = false;
}
Centerscaleanimation. setduration (2000 );
Centerscaleanimation. setfillafter (true );
// Number of animation repetitions (-1 indicates repetition)
// Centerscaleanimation. setrepeatcount (-1 );
Centerscaleanimation. setanimationlistener (New animationlistener (){

@ Override
Public void onanimationstart (animation ){
// Todo auto-generated method stub

}

@ Override
Public void onanimationrepeat (animation ){
// Todo auto-generated method stub

}

@ Override
Public void onanimationend (animation ){
Center. setenabled (true );
// Todo auto-generated method stub

}
});
// Picture configuration animation for drinking coffee
Center. setanimation (centerscaleanimation );

// Animation starts
Centerscaleanimation. startnow ();

Center. setenabled (false );
}
}

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.