package com.saiermeng.annimation;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
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.ImageView;
public class MainActivity extends Activity {
private ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv_xfj);
}
public void alpha(View v){
AlphaAnimation aa = new AlphaAnimation(0, 1.0f);
aa.setRepeatCount(2);
aa.setRepeatMode(AlphaAnimation.REVERSE);
aa.setDuration(3000);
iv.startAnimation(aa);
}
public void rotate(View v) {
RotateAnimation ra = new RotateAnimation(0, 360,
1, 0.5f,
1, 0.5f);
ra.setRepeatCount(2);
ra.setRepeatMode(AlphaAnimation.REVERSE);
ra.setDuration(3000);
iv.startAnimation(ra);
}
public void scale(View v) {
ScaleAnimation sa = new ScaleAnimation(0, 2.0f, 0, 2.0f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
sa.setRepeatCount(2);
sa.setRepeatMode(AlphaAnimation.REVERSE);
sa.setDuration(3000);
iv.startAnimation(sa);
}
public void trans(View v) {
TranslateAnimation ta = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_SELF, 0,
TranslateAnimation.RELATIVE_TO_SELF, 3.0f,
TranslateAnimation.RELATIVE_TO_SELF, 0,
TranslateAnimation.RELATIVE_TO_SELF, 3.0f);
ta.setRepeatCount(2);
ta.setRepeatMode(AlphaAnimation.REVERSE);
ta.setDuration(3000);
iv.startAnimation(ta);
}
public void set(View v) {
AnimationSet set =new AnimationSet(false);
AlphaAnimation aa = new AlphaAnimation(0, 1.0f);
aa.setRepeatCount(2);
aa.setRepeatMode(AlphaAnimation.REVERSE);
aa.setDuration(3000);
set.addAnimation(aa);
RotateAnimation ra = new RotateAnimation(0, 360,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
ra.setRepeatCount(2);
ra.setRepeatMode(AlphaAnimation.REVERSE);
ra.setDuration(3000);
set.addAnimation(ra);
ScaleAnimation sa = new ScaleAnimation(0, 2.0f, 0, 2.0f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
sa.setRepeatCount(2);
sa.setRepeatMode(AlphaAnimation.REVERSE);
sa.setDuration(3000);
set.addAnimation(sa);
TranslateAnimation ta = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_SELF, 0,
TranslateAnimation.RELATIVE_TO_SELF, 3.0f,
TranslateAnimation.RELATIVE_TO_SELF, 0,
TranslateAnimation.RELATIVE_TO_SELF, 3.0f);
ta.setRepeatCount(2);
ta.setRepeatMode(AlphaAnimation.REVERSE);
ta.setDuration(3000);
set.addAnimation(ta);
iv.startAnimation(set);
}
}