-
Notifications
You must be signed in to change notification settings - Fork 14
/
AnimationUtils.kt
93 lines (86 loc) · 2.65 KB
/
AnimationUtils.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.excellence.basetoolslibrary.utils
import android.view.View
import android.view.animation.AlphaAnimation
import android.view.animation.Animation.RELATIVE_TO_SELF
import android.view.animation.ScaleAnimation
import android.view.animation.TranslateAnimation
/**
* <pre>
* author : VeiZhang
* blog : http://tiimor.cn
* time : 2022/5/18
* desc : 补间动画
* </pre>
*/
object AnimationUtils {
private const val ANIM_DURATION = 200
private const val SCALE = 1.2f
/**
* 放大缩小动画
*
* @param view
* @param isScaled
*/
@JvmOverloads
@JvmStatic
fun scaleView(view: View, isScaled: Boolean,
fromX: Float = 1F,
fromY: Float = 1F,
toX: Float = SCALE,
toY: Float = SCALE,
duration: Long = ANIM_DURATION.toLong()) {
if (isScaled) {
val animation = ScaleAnimation(fromX, toX, fromY, toY,
RELATIVE_TO_SELF, 0F,
RELATIVE_TO_SELF, 0F)
animation.duration = duration
view.startAnimation(animation)
} else {
val animation = ScaleAnimation(toX, fromX, toY, fromY,
RELATIVE_TO_SELF, 0F,
RELATIVE_TO_SELF, 0F)
animation.duration = duration
view.startAnimation(animation)
}
}
/**
* 平移动画
*/
@JvmOverloads
@JvmStatic
fun translateView(view: View, translate: Boolean,
fromX: Float = 0F,
fromY: Float = 0F,
toX: Float,
toY: Float,
duration: Long = ANIM_DURATION.toLong()) {
if (translate) {
val animation = TranslateAnimation(fromX, toX, fromY, toY)
animation.duration = duration
view.startAnimation(animation)
} else {
val animation = TranslateAnimation(fromX, toX, fromY, toY)
animation.duration = duration
view.startAnimation(animation)
}
}
/**
* 透明度动画
*/
@JvmOverloads
@JvmStatic
fun alphaView(view: View, alpha: Boolean,
from: Float = 1F,
to: Float,
duration: Long = ANIM_DURATION.toLong()) {
if (alpha) {
val animation = AlphaAnimation(from, to)
animation.duration = duration
view.startAnimation(animation)
} else {
val animation = AlphaAnimation(to, from)
animation.duration = duration
view.startAnimation(animation)
}
}
}