main20

来源:互联网 发布:网络效应多选题及答案 编辑:程序博客网 时间:2024/06/05 09:27
package com.example.demoall;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.view.animation.AnimationSet;import android.view.animation.RotateAnimation;import android.view.animation.ScaleAnimation;import android.view.animation.TranslateAnimation;import android.widget.Button;import android.widget.ImageView;public class Main20 extends Activity implements OnClickListener{private Button main20_rotate;private ImageView main20_image;private Button main20_scale;private Button main20_alpha;private Button main20_translate;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main20);main20_rotate=(Button)this.findViewById(R.id.main20_rotate);  //旋转main20_rotate.setOnClickListener(this);main20_scale=(Button)this.findViewById(R.id.main20_scale);  //缩放main20_scale.setOnClickListener(this);main20_alpha=(Button)this.findViewById(R.id.main20_alpha);  //淡入淡出main20_alpha.setOnClickListener(this);main20_translate=(Button)this.findViewById(R.id.main20_translate);  //移动main20_translate.setOnClickListener(this);main20_image=(ImageView)this.findViewById(R.id.main20_image);}@Overridepublic void onClick(View v) {AnimationSet animationSet=new AnimationSet(true);switch (v.getId()) {case R.id.main20_rotate:     //旋转RotateAnimation rotate=new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);rotate.setDuration(2000);animationSet.addAnimation(rotate);main20_image.startAnimation(animationSet);break;case R.id.main20_scale:     //缩放/** * 参数1:x轴的初始值 * 参数2:x轴收缩后的值 * 参数3:y轴初始值 * 参数4:y轴收缩后的值 * 参数5:x轴的坐标类型 * 参数6:x轴的值,0.5f表明是以自身这个控件的一半长度为x轴 * 参数7:y轴的坐标类型 * 参数8:y轴的值,0.5f表明是以自身这个控件的一半长度为y轴 */ScaleAnimation scale=new ScaleAnimation(0, 0.1f, 0, 0.1f,Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);scale.setDuration(3000);animationSet.addAnimation(scale);main20_image.startAnimation(animationSet);break;case R.id.main20_alpha:   //淡入淡出//参数从完全透明到完全不透明AlphaAnimation alpha=new AlphaAnimation(1, 0);alpha.setDuration(1000);animationSet.addAnimation(alpha);main20_image.startAnimation(animationSet);break;case R.id.main20_translate:   // 移动/** * 参数1-2:x轴开始位置 * 参数3-4:y轴开始位置 * 参数5-6:x轴结束位置 * 参数7-8:y轴结束位置 *  */TranslateAnimation translate=new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f,Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0f,Animation.RELATIVE_TO_SELF, 0.5f);translate.setDuration(1000);animationSet.addAnimation(translate);main20_image.startAnimation(animationSet);break;default:break;}}}

0 0
原创粉丝点击