补间动画

本文介绍了如何使用Android中的补间动画来实现ImageView的各种动画效果,包括透明度变化、旋转、缩放和平移,并提供了具体的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

找到控件: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);
}
补间动画:
	动画效果不会改变控件的真实的坐标。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值