找到控件:ImageView
ImageView iv = (ImageView) findViewById(R.id.iv);
//实现iv透明的效果
public void click1(){
//new AlphaAnimation(float fromAlpha, float toAlpha);
1.0意味着完全不透明,0.0意味着完全透明
AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);
//设置动画执行的时长
animation.setDuration(2000);
//设置重复的次数
animation.setRepeatCount(1);
animation.setRepeatMode(Animation.REVERSE);
//开始执行动画
iv.startAnimation(animation);
}
//旋转
public void click2() {
//fromDegrees 开始的角度,toDegrees结束的角度
//RotateAnimation animation = new RotateAnimation(0,360);//旋转360度
RotateAnimation animation= new RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue,
int pivotYType, float pivotYValue);
//以自己为中心旋转360度
RotateAnimation animation = new RotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(2000);
animation.setRepeatCount(1);
//设置动画执行的模式
animation.setRepeatMode(Animation.REVERSE);
iv.setAnimation(animation);
}
//缩放
public void click3(){
ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.5f, 1.0f, 0.5f, Animation.RELATIVE_TO_SELF, 0.2f, Animation.RELATIVE_TO_SELF, 0.2f);
scaleAnimation.setRepeatCount(1);
scaleAnimation.setDuration(2000);
scaleAnimation.setRepeatMode(Animation.REVERSE);
iv.setAnimation(scaleAnimation);
}
//位移
public void click4(){
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0,Animation.RELATIVE_TO_PARENT,0.2f,Animation.RELATIVE_TO_PARENT,0.2f);
translateAnimation.setDuration(2000);
//当动画结束后,动画停留在结束位置
translateAnimation.setFillAfter(true);
iv.setAnimation(translateAnimation);
}
补间动画:
动画效果不会改变控件的真实的坐标。