Code for calling the four animation effects of Android

Source: Internet
Author: User

(1) The main. xml Code is as follows: (declare four button controls)

XML code:Copy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<AbsoluteLayout
Android: id = "@ + id/widget32"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Xmlns: android = "http://schemas.android.com/apk/res/android"
>
<TextView
Android: id = "@ + id/widget29"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello"
Android: layout_x = "0px"
Android: layout_y = "0px"
>
</TextView>
<Button
Android: id = "@ + id/button_Alpha"
Android: layout_width = "150px"
Android: layout_height = "150px"
Android: text = "Alpha Animation"
Android: textSize = "50px"
Android: layout_x = "0px"
Android: layout_y = "30px">
</Button>
<Button
Android: id = "@ + id/button_Scale"
Android: layout_width = "150px"
Android: layout_height = "150px"
Android: text = "Scale Animation"
Android: textSize = "50px"
Android: layout_x = "0px"
Android: layout_y = "180px">
</Button>
<Button
Android: layout_width = "150px"
Android: layout_height = "150px"
Android: text = "Translate Animation"
Android: layout_x = "161px"
Android: layout_y = "30px"
Android: textSize = "30px"
Android: id = "@ + id/button_Translate">
</Button>
<Button
Android: id = "@ + id/button_Rotate"
Android: layout_width = "150px"
Android: layout_height = "150px"
Android: text = "Rotate Animation"
Android: layout_y = "180px"
Android: layout_x = "161px"
Android: textSize = "44px">
</Button>
</AbsoluteLayout>

Java code:Copy codeThe Code is as follows: 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. AnimationUtils;
Import android. widget. Button;

Public class myActionAnimation extends Activity implements OnClickListener {
/** Called when the activity is first created .*/
Private Button button_alpha;
Private Button button_scale;
Private Button button_translate;
Private Button button_rotate;
Private Animation myAnimation_Alpha;
Private Animation myAnimation_Scale;
Private Animation myAnimation_Translate;
Private Animation myAnimation_Rotate;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );

Button_alpha = (Button) findViewById (R. id. button_Alpha );
Button_alpha.setOnClickListener (this );

Button_scale = (Button) findViewById (R. id. button_Scale );
Button_scale.setOnClickListener (this );

Button_translate = (Button) findViewById (R. id. button_Translate );
Button_translate.setOnClickListener (this );

Button_rotate = (Button) findViewById (R. id. button_Rotate );
Button_rotate.setOnClickListener (this );
}
Public void onClick (View button ){
// TODO Auto-generated method stub
Switch (button. getId ()){
Case R. id. button_Alpha :{
MyAnimation_Alpha = AnimationUtils. loadAnimation (this, R. layout. my_alpha_action );
Button_alpha.startAnimation (myAnimation_Alpha );
}
Break;
Case R. id. button_Scale :{
MyAnimation_Scale = AnimationUtils. loadAnimation (this, R. layout. my_scale_action );
Button_scale.startAnimation (myAnimation_Scale );
}
Break;
Case R. id. button_Translate :{
MyAnimation_Translate = AnimationUtils. loadAnimation (this, R. layout. my_translate_action );
Button_translate.startAnimation (myAnimation_Translate );
}
Break;
Case R. id. button_Rotate :{
MyAnimation_Rotate = AnimationUtils. loadAnimation (this, R. layout. my_rotate_action );
Button_rotate.startAnimation (myAnimation_Rotate );
}
Break;

Default:
Break;
}
}
}

:

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.