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);
}