findViewById(R.id.translate).setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {//左右晃動 or 上下晃動 or 斜著TranslateAnimation animation = new TranslateAnimation(0,mButton.getWidth() + x, 0, 0);animation.setInterpolator(new CycleInterpolator(2f));animation.setDuration(10000);//animation.setFillEnabled(true); //停止動畫button停在那裡。//animation.setFillAfter(true);//animation.setFillBefore(true);animation.initialize(mButton.getWidth(), mButton.getHeight(),mButton.getWidth(), mButton.getHeight());mButton.startAnimation(animation);animation.setAnimationListener(new AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationRepeat(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {animation = new TranslateAnimation(0, mButton.getWidth(), 0, 0);animation.setInterpolator(new CycleInterpolator(2f));animation.setDuration(10000);mButton.startAnimation(animation);}});}});findViewById(R.id.rotate).setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {//旋轉RotateAnimation animation = new RotateAnimation(0, 720,Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);animation.setDuration(10000);mButton.startAnimation(animation);}});findViewById(R.id.scale).setOnClickListener(new OnClickListener() {//比例放大@Overridepublic void onClick(View v) {
//參數 1.開始的x軸方向比例2.結束時的x軸方向比例3.y的開始4.y的結束5.開始時的中心座標(以自己為標準)6.以自己的水品方向的2倍座標為中心7.y的8.自己y方向的0.5倍座標及自己的y方向的中心點。
ScaleAnimation animation = new ScaleAnimation(0, 1f, 0, 1f,Animation.RELATIVE_TO_SELF, 2,Animation.RELATIVE_TO_SELF, 0.5f);animation.setDuration(10000);mButton.startAnimation(animation);}});findViewById(R.id.alpha).setOnClickListener(new OnClickListener() {//透明度@Overridepublic void onClick(View v) {AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);alphaAnimation.setDuration(10000);alphaAnimation.setRepeatCount(-1);alphaAnimation.setRepeatMode(Animation.REVERSE);mButton.startAnimation(alphaAnimation);alphaAnimation.setAnimationListener(new AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationRepeat(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {}});}});