补间动画

含义:所谓补间动画又叫做中间帧动画,渐变动画,只要建立起始和结束的画面,中间部分由软件自动生成,省去了中间动画制作的复杂过程

1.透明效果

代码实现

//AlphaAnimation aa = new AlphaAnimation(1,0);
//aa.setDuration(5000);
//aa.setRepeatCount(1);
//aa.setRepeatMode(Animation.REVERSE);
//iv.startAnimation(aa);//启动动画

xml实现

Animation aa = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.alpha);//加载xml文件动画参数
iv.startAnimation(aa);//启动动画

res/anim文件下

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"//动画持续时间
android:fromAlpha="1.0"//开始值,1.0表示显示
android:repeatCount="1"//执行次数
android:toAlpha="0.0">//结束值,0.0表示不显示
</alpha>

2.旋转效果

代码实现

//RotateAnimation ra = new RotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
//ra.setDuration(2000);
//ra.setRepeatCount(1);
//ra.setRepeatMode(Animation.REVERSE);
//iv.startAnimation(ra);

xml实现

Animation ra = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate);
iv.startAnimation(ra);

res/anim文件下

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="360"//旋转开始角度
    android:toDegrees="0"//旋转结束角度
    android:pivotX="10%"//旋转中心点,x坐标,从左上角开始x轴10%开始
    android:pivotY="10%"//旋转中心点,y坐标,从左上角开始y轴10%开始
    android:repeatCount="1"
android:repeatMode = "reverse"//重复模式,
reverse动画执行完后回到原来位置
android:duration="2000" ></rotate>

3.缩放效果

代码实现
//ScaleAnimation sa = new ScaleAnimation(1.0f, 2.0f, 1.0f, 2.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//sa.setDuration(2000);
//sa.setRepeatCount(1);
//sa.setRepeatMode(Animation.REVERSE);
//iv.startAnimation(sa);

xml实现
Animation sa = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.scale);
iv.startAnimation(sa);

res/anim文件下


<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXScale="1.0"//开始缩放位置x坐标
    android:toXScale="5.0"//结束缩放位置x坐标,相当于倍数
    android:fromYScale="1.0"//开始缩放位置y坐标
    android:toYScale="5.0"//结束缩放位置y坐标,相当于倍数
    android:pivotX="50%"//缩放中心点,x坐标,从左上角x轴10%开始
    android:pivotY="50%"//缩放中心点,y坐标,从左上角y轴10%开始
android:repeatMode="reverse" android:repeatCount="1" android:duration="2000" ></scale>

4.平移效果

代码实现

//TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0.2f);
//ta.setDuration(2000);
ta.setFillAfter(true);
//ta.setRepeatMode(Animation.REVERSE);
// iv.startAnimation(ta);

xml实现

Animation ta= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.translate);
iv.startAnimation(ta);

res/anim文件下

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0%p"//平移x轴开始位置
    android:toXDelta="50%p"//平移x轴结束位置
    android:fromYDelta="0%p"//平移y轴开始位置
    android:toYDelta="50%p"//平移y轴结束位置
    android:fillAfter="true"//平移后不恢复原状,停在平移后位置
    android:duration="2000"
    >

</translate>

5.补间动画集

 

代码实现

//       AnimationSet set = new AnimationSet(false);
//
//        AlphaAnimation aa = new AlphaAnimation(1, 0);
//        aa.setDuration(2000);
//        aa.setRepeatCount(1);
//        aa.setRepeatMode(Animation.REVERSE);
//        set.addAnimation(aa);
//
//        RotateAnimation ra = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//        ra.setDuration(2000);
//        ra.setRepeatCount(1);
//        ra.setRepeatMode(Animation.REVERSE);
//        set.addAnimation(ra);
//
//
//        ScaleAnimation sa = new ScaleAnimation(1.0f, 2.0f, 1.0f, 2.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//        sa.setDuration(2000);
//        sa.setRepeatCount(1);
//        sa.setRepeatMode(Animation.REVERSE);
//        set.addAnimation(sa);
//
//        TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0.2f);
//        ta.setDuration(2000);
//        //ta.setFillAfter(true);
//        ta.setRepeatMode(Animation.REVERSE);
//        set.addAnimation(ta);
//
//        iv.startAnimation(set);


xml实现

Animation set = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.set);
iv.startAnimation(set);

res/anim文件下
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:duration="2000"
        android:fromAlpha="1.0"
        android:repeatMode="reverse"
        android:toAlpha="0.0">

    </alpha>

    <rotate
        android:duration="2000"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="1"
        android:repeatMode="reverse"
        android:toDegrees="360"></rotate>

    <scale
        android:duration="2000"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:repeatCount="1"
        android:repeatMode="reverse"
        android:toXScale="2.0"
        android:toYScale="2.0"></scale>

    <translate
        android:duration="2000"
        android:fillAfter="true"
        android:fromXDelta="0%p"
        android:fromYDelta="0%p"
        android:toXDelta="0%p"
        android:toYDelta="20%p"
        ></translate>
</set>











  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值