1动画涉及到的知识点
Scale动画
Scale是Android的尺寸缩放动画,继承自基类Animation
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0.0" #起始x尺寸比例
android:toXScale="1.4" #最终x尺寸比例
android:fromYScale="0.0" #起始y尺寸比例
android:toYScale="1.4" #最终y尺寸比例
android:pivotX="50%" #缩放起点x轴坐标,取值可以是数值(50)、百分数(50%)、百
分数p(50%p),当取值为数值时,缩放起点为View左上角坐标
加具体数值像素,当取值为百分数时,表示在当前View左上角坐
加上View宽度的具体百分比,当取值为百分数p时,表示在View
左上角坐标加上父控件宽度的具体百分比
android:pivotY="50%" #同上
android:duration="700" #动画持续时间,毫秒为单位
android:fillAfter="true" #动画结束后,保持结束时的状态
android:fillBefore="true" #动画结束后,恢复为初始状态
android:fillEnabled="true" #效果同上
android:repeatCount="5" #重复次数,取值为-1时无限重复,默认动画执行一次
android:repeatMode ="reverse" #重复模式,有reverse和restart两个值,前者为倒序回放,后者为重新开始
android::interpolator="@android:anim/accelerate_decelerate_interpolator" #插值器,后面单独讲
/>
Alpha动画
Alpha是Andriod透明度渐变动画,其基类为Animation类。
<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0" #起始透明度,取值范围0.0--1.0 ,从完全透明到完全不透明
android:toAlpha="0.1" #结束透明度,取值范围同上
android:duration="700" #动画持续时间,毫秒为单位
android:fillAfter="true" #动画结束后,保持结束时的状态
android:fillBefore="true" #动画结束后,恢复为初始状态
android:fillEnabled="true" #效果同上
android:repeatCount="5" #重复次数,取值为-1时无限重复,默认动画执行一次
android:repeatMode ="reverse" #重复模式,有reverse和restart两个值,前者为倒序回放,后者为重新开始
android::interpolator="@android:anim/accelerate_decelerate_interpolator" #插值器,后面单独讲
/>
Rotate动画
旋转动画,继承自基类Animaton
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0" #初始角度
android:toDegrees="540" #结束时角度,值为正时顺时针旋转,值为负时逆时针旋转
android:pivotX="50%" #旋转中心x轴坐标,取值可以是数值(50)、百分数(50%)、百
分数p(50%p),当取值为数值时,缩放起点为View左上角坐标
加具体数值像素,当取值为百分数时,表示在当前View左上角坐
加上View宽度的具体百分比,当取值为百分数p时,表示在View
左上角坐标加上父控件宽度的具体百分比
android:pivotY="50%" #同上
android:duration="700" #动画持续时间,毫秒为单位
android:fillAfter="true" #动画结束后,保持结束时的状态
android:fillBefore="true" #动画结束后,恢复为初始状态
android:fillEnabled="true" #效果同上
android:repeatCount="5" #重复次数,取值为-1时无限重复,默认动画执行一次
android:repeatMode ="reverse" #重复模式,有reverse和restart两个值,前者为倒序回放,后者为重新开始
android:interpolator="@android:anim/accelerate_decelerate_interpolator" #插值器,后面单独讲
/>
Translate动画
顾名思义,Translate动画就是位移动画,也是集成自基类Animation。
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0" #起始x轴坐标位置
android:toXDelta="50" #结束时x轴坐标位置
android:fromYDelta="0" #起始Y轴坐标位置
android:toYDelta="200" #结束时Y轴坐标位置
android:duration="700" #动画持续时间,毫秒为单位
android:fillAfter="true" #动画结束后,保持结束时的状态
android:fillBefore="true" #动画结束后,恢复为初始状态
android:fillEnabled="true" #效果同上
android:repeatCount="5" #重复次数,取值为-1时无限重复,默认动画执行一次
android:repeatMode ="reverse" #重复模式,有reverse和restart两个值,前者为倒序回放,后者为重新开始
android::interpolator="@android:anim/accelerate_decelerate_interpolator" #插值器,后面单独讲
/>
Set动画
set本身没有什么新的属性,但可以让它们四个动画同时发挥作用,让效果变得更加酷炫。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="700" #动画持续时间,毫秒为单位,set中会覆盖子动画该属性
android:fillAfter="true" #动画结束后,保持结束时的状态
android:fillBefore="true" #动画结束后,恢复为初始状态
android:fillEnabled="true" #效果同上
android:repeatCount="5" #此属性无效对于set无效
android:repeatMode ="reverse" #重复模式,有reverse和restart两个值,前者为倒序回放,后者为重新开始,set中会覆盖子动画该属性
android:interpolator="@android:anim/accelerate_decelerate_interpolator" #插值器,后面单独讲
>
<alpha
android:fromAlpha="0.2"
android:duration="2000"
android:toAlpha="1.0"/>
<scale android:fromXScale="0.5"
android:toXScale="1.5"
android:fromYScale="0.5"
android:toYScale="1.5"
android:pivotX="50%"
android:duration="5000"
android:repeatMode="restart"
android:repeatCount="2"
android:pivotY="50%"/>
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:duration="500"
android:pivotX="50%"
android:pivotY="50%"/>
</set>
参考文章
https://blog.csdn.net/wenwen091100304/article/details/53471592