android tween animation 补间动画

public class MainActivity extends Activity {
private ImageView imageView;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.image);
}


/**
* 透明度
* 
* @param view
*/
public void click1(View view) {
// 两个参数分别代表动画图片开始的透明度和结束的透明度
AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
// 设置动画的时间长度
animation.setDuration(2000);
// 设置动画播放的重复次数,设置为2代表一共播放3次
animation.setRepeatCount(2);
// 设置重复的模式,Animation.REVERSE代表往返重复
animation.setRepeatMode(Animation.REVERSE);
imageView.startAnimation(animation);
}


/**
* 缩放
* 
* @param view
*/
public void click2(View view) {
// 0.2f(X或Y方向的开始缩放大小为图片的20%) 1.0f(X或Y方向的结束缩放大小为图片的100%)
// Animation.RELATIVE_TO_SELF(以自身相关来改变) 0.5f(X和Y以自身的中心圆点来缩放)
ScaleAnimation animation = new ScaleAnimation(0.2f, 1.0f, 0.2f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(2000);
animation.setRepeatCount(2);
animation.setRepeatMode(Animation.REVERSE);
imageView.startAnimation(animation);


}


/**
* 旋转
* 
* @param view
*/
public void click3(View view) {
RotateAnimation animation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(2000);
animation.setRepeatCount(2);
animation.setRepeatMode(Animation.REVERSE);
imageView.startAnimation(animation);


}
 
/**
* 平移
* 
* @param view
*/
public void click4(View view) {
// 水平移动
TranslateAnimation animation = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
animation.setDuration(2000);
animation.setRepeatCount(2);
animation.setRepeatMode(Animation.REVERSE);
imageView.startAnimation(animation);
}


/**
* 组合
* 
* @param view
*/
public void click5(View view) {
AnimationSet animationSet = new AnimationSet(false);
ScaleAnimation scaleAnimation = new ScaleAnimation(0.2f, 1.0f, 0.2f,
1.0f, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(2000);
scaleAnimation.setRepeatCount(2);
scaleAnimation.setRepeatMode(Animation.REVERSE);

RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
rotateAnimation.setDuration(2000);
rotateAnimation.setRepeatCount(2);
rotateAnimation.setRepeatMode(Animation.REVERSE);

TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
translateAnimation.setDuration(2000);
translateAnimation.setRepeatCount(2);
translateAnimation.setRepeatMode(Animation.REVERSE);

animationSet.addAnimation(translateAnimation);
animationSet.addAnimation(rotateAnimation);
animationSet.addAnimation(scaleAnimation);

                // 把平移、旋转、缩放结合在一起的动画
imageView.startAnimation(animationSet);

}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值