day06_动画

day06_动画

动画的详解

介绍总览 https://www.jianshu.com/p/35d25cc205e7

一、补间动画

介绍 https://www.jianshu.com/p/733532041f46
属性
在这里插入图片描述
其中AnimationSet是其余几种以及其他AnimationSet的组合
基本属性:在这里插入图片描述
Duration:持续时间,单位是毫秒
Interpolator:插值器
插值器列表
在这里插入图片描述

1、透明度

Alpha属性(透明度)
在这里插入图片描述示例
alpha.xml

<alpha xmlns:android="http://schemas.android.com/apk/res/android"

    android:fromAlpha="1"
    android:toAlpha="0"
    android:duration="2000"
    >
</alpha>

java代码

    public void alpha(View view) {
        //1.创建xml文件实现补间动画   透明
//        Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
//        img.startAnimation(animation);
        //2.java代码实现补间动画   透明
        AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
        alphaAnimation.setDuration(2000);  // 动画时间
        alphaAnimation.setFillAfter(true); //是否保留最后结果
        alphaAnimation.setRepeatCount(1);  //重复次数
        img.startAnimation(alphaAnimation);
    }
2、旋转

Rorate属性(旋转)
在这里插入图片描述
示例
rorate.xml

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fromDegrees="0"
    android:toDegrees="720"
    android:pivotX="50%"
    android:pivotY="50%"
    >
</rotate>
<!--   fromDegrees 角度 -->
<!--    旋转中心点 pivotX pivotY-->
public void rotate(View view) {
        //1.创建xml文件实现补间动画   旋转
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate);
        img.startAnimation(animation);
        //2.java代码实现补间动画   旋转
    }
3、缩放

Scale属性(缩放)
在这里插入图片描述
示例
scale.xml

<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXScale="1"
    android:toXScale="2"
    android:fromYScale="1"
    android:toYScale="2"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="2000"
    >
</scale>
    public void scale(View view) {
        //1.创建xml文件实现补间动画   缩放
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale);
        img.startAnimation(animation);
        //2.java代码实现补间动画   缩放
    }
4、位移

Translate 属性
在这里插入图片描述
示例
translate.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromYDelta="0"
    android:toYDelta="300"
    android:fromXDelta="0"
    android:toXDelta="300"
    android:duration="2000"
    >
</translate>
public void trans(View view) {
        //1.创建xml文件实现补间动画   位移
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.translate);
        img.startAnimation(animation);
        //2.java代码实现补间动画   位移
    }
5、组合动画

示例

    public void hebing(View view) {
        Animation alpha = AnimationUtils.loadAnimation(this, R.anim.alpha);
        Animation scale = AnimationUtils.loadAnimation(this, R.anim.scale);
        AnimationSet animationSet = new AnimationSet(true);
        animationSet.addAnimation(alpha);
        animationSet.addAnimation(scale);
        img.startAnimation(animationSet);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值